
    +hw                        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#  S
SK$J%r%J&r&J'r'  S
SK(J)r)  SSK*J+r+  \" 5       (       a  S SK,J-s  J.r/  Sr0OSr0\Rb                  " \25      r3\" 5       (       a  S SK4J5r5  \" 5       (       a  S SK6r6Sr7    SS\	\8   S\	\\9\Rt                  4      S\	\\8      S\	\\;      4S jjr< " S S\"\+5      r=g)    N)CallableListOptionalTupleUnion)T5EncoderModelT5Tokenizer   )PixArtImageProcessor)AutoencoderKLPixArtTransformer2DModel)KarrasDiffusionSchedulers)BACKENDS_MAPPING	deprecateis_bs4_availableis_ftfy_availableis_torch_xla_availableloggingreplace_example_docstring)randn_tensor   )DiffusionPipelineImagePipelineOutput)ASPECT_RATIO_256_BINASPECT_RATIO_512_BINASPECT_RATIO_1024_BIN)ASPECT_RATIO_2048_BIN   )PAGMixinTF)BeautifulSoupaB  
    Examples:
        ```py
        >>> import torch
        >>> from diffusers import AutoPipelineForText2Image

        >>> pipe = AutoPipelineForText2Image.from_pretrained(
        ...     "PixArt-alpha/PixArt-Sigma-XL-2-1024-MS",
        ...     torch_dtype=torch.float16,
        ...     pag_applied_layers=["blocks.14"],
        ...     enable_pag=True,
        ... )
        >>> pipe = pipe.to("cuda")

        >>> prompt = "A small cactus with a happy face in the Sahara desert"
        >>> image = pipe(prompt, pag_scale=4.0, guidance_scale=1.0).images[0]
        ```
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           k/home/james-whalen/.local/lib/python3.13/site-packages/diffusers/pipelines/pag/pipeline_pag_pixart_sigma.pyretrieve_timestepsr5   U   s}   > !3tuu'3w/@/@AXAX/Y/d/d/i/i/k+ll .y/B/B.C Da b  	M)MfM''	!)n )) 
	 C(9(9):Q:Q(R(](](b(b(d$ee.y/B/B.C D_ `  	GvGG''	!)n )) 	 3MFMfM''	))    c            9         ^  \ rS rSrSr\R                  " S5      rSS/rSr	 S1S\
S\S\S\S	\S
\\\\   4   4U 4S jjjr          S2S\\\\   4   S\S\S\S\\R.                     S\\R0                     S\\R0                     S\\R0                     S\\R0                     S\S\4S jjrS r    S3S jrS4S jrS rS5S jr\R>                  " 5       \ " \!5                               S6S\\\\   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,\"S-\"S.\\%\&4   44S/ jj5       5       r'S0r(U =r)$ )7PixArtSigmaPAGPipeline   z
[PAG pipeline](https://huggingface.co/docs/diffusers/main/en/using-diffusers/pag) for text-to-image generation
using PixArt-Sigma.
u5   [#®•©™&@·º½¾¿¡§~\)\(\]\[\}\{\|\\/\*]{1,}	tokenizertext_encoderztext_encoder->transformer->vaevaetransformerr0   pag_applied_layersc                 &  > [         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
        U R                  U5        g )N)r:   r;   r<   r=   r0   r<   r   r      )vae_scale_factor)super__init__register_modulesgetattrr/   r<   configblock_out_channelsrA   r   image_processorset_pag_applied_layers)selfr:   r;   r<   r=   r0   r>   r.   s          r4   rC   PixArtSigmaPAGPipeline.__init__   s     	hq 	 	
 W^^bdikoVpVpc$((//*L*L&MPQ&Q Rvw3TEZEZ[##$67r6   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 300): Maximum sequence length to use for the prompt.
mask_featurezThe 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.z1.0.0F)standard_warnN)rT   
max_lengthTpt)paddingrY   
truncationadd_special_tokensreturn_tensorslongest)r[   r^   r   zZThe following part of your input was truncated because T5 can only handle sequences up to z	 tokens: )attention_maskr   dtyper"   )r[   rY   r\   return_attention_maskr]   r^   )r   _execution_device_text_preprocessingr:   	input_idsshapetorchequalbatch_decodeloggerwarningra   tor;   rc   r=   repeatview
isinstancestr)rJ   rL   rM   rN   rO   r"   rP   rQ   rR   rS   rT   rU   r1   deprecation_messagerY   text_inputstext_input_idsuntruncated_idsremoved_textrc   bs_embedseq_len_uncond_tokensuncond_inputs                            r4   encode_prompt$PixArtSigmaPAGPipeline.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kr6   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*   r0   stepr,   r-   )rJ   r   r   accepts_etaextra_step_kwargsaccepts_generators         r4   prepare_extra_step_kwargs0PixArtSigmaPAGPipeline.prepare_extra_step_kwargsF  s     s7#4#4T^^5H5H#I#T#T#Y#Y#[\\'*e$ (3w/@/@ATAT/U/`/`/e/e/g+hh-6k*  r6   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'   rq   inttyperr   listrh   )
rJ   rL   heightwidthrN   callback_stepsrP   rQ   rR   rS   s
             r4   check_inputs#PixArtSigmaPAGPipeline.check_inputsX  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$r6   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   rT   rJ   s    r4   process;PixArtSigmaPAGPipeline._text_preprocessing.<locals>.process  sH    **40**40 K zz|))+Kr6   )
r   rl   rm   r   formatr   rq   tupler   rr   )rJ   r   rT   r   ts   ` `  r4   rf   *PixArtSigmaPAGPipeline._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+$)rr   ulunquote_plusr   r   resubr    r   bad_punct_regexcompiler/   findallr   fix_texthtmlunescape)rJ   captionregex2s      r4   r   %PixArtSigmaPAGPipeline._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}}r6   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"   rc   )
r   rA   rq   r   r/   r'   r   rn   r0   init_noise_sigma)
rJ   
batch_sizenum_channels_latentsr   r   rc   r"   r   latentsrh   s
             r4   prepare_latents&PixArtSigmaPAGPipeline.prepare_latents(  s     K4000J$///	
 i&&3y>Z+GA#i.AQ R&<'gi 
 ?"5fZGjj(G NN;;;r6   r!   r#   r$   guidance_scaler   r   r   r   r   output_typereturn_dictcallbackr   use_resolution_binning	pag_scalepag_adaptive_scalereturnc                    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OU 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U l        UU l        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 R*                  (       a&  U R-                  XU5      nU R-                  UUU5      nO4U(       a-  [.        R0                  " X/S	S9n[.        R0                  " UU/S	S9n[3        U R4                  UUXE5      u  pCU R                   R                  R6                  n U R9                  UU-  U UU	UR:                  UUU5      nU R*                  (       a0  U R                   R<                  n!U R?                  U R@                  US9  U RC                  X5      n"SSS.n#[E        [#        U5      X0R4                  RF                  -  -
  S	5      n$U RI                  US9 n%[K        U5       GH  u  n&n'[.        R0                  " U/UR$                  S	   UR$                  S	   -  -  5      n(U R4                  RM                  U(U'5      n(U'n)[.        RN                  " U)5      (       d  U(RP                  RR                  S:H  n*U(RP                  RR                  S:H  n+[        U)[T        5      (       a/  U*(       d  U+(       a  [.        RV                  O[.        RX                  n,O.U*(       d  U+(       a  [.        RZ                  O[.        R\                  n,[.        R^                  " U)/U,U(RP                  S9n)O7[#        U)R$                  5      S	:X  a  U)S   Ra                  U(RP                  5      n)U)Rc                  U(R$                  S	   5      n)U R                  U(UUU)U#SS9S	   n-U R*                  (       a  U Re                  U-UUU)5      n-O&U(       a  U-Rg                  S5      u  n.n/U.UU/U.-
  -  -   n-U R                   R                  Rh                  S-  U :X  a  U-Rg                  SSS9S	   n-OU-n-U R4                  Rj                  " 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 R4                  RF                  -  S	:X  a@  U%Rm                  5         Ub-  U&U-  S	:X  a$  U&[o        U R4                  SS5      -  n0U" U0U'U5        [p        (       d  GM  [r        Rt                  " 5         GM     SSS5        US:X  db  U Rv                  Ry                  XRv                  R                  Rz                  -  SS9S	   n1U(       a  U R                  R}                  U1WW5      n1OUn1US:X  d  U R                  R                  U1US9n1U R                  5         U R*                  (       a  U R                   R                  W!5        U(       d  U14$ [        U1S9$ ! , (       d  f       N= f)uV  
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-Sigma 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 300): Maximum sequence length to use with the `prompt`.
    pag_scale (`float`, *optional*, defaults to 3.0):
        The scale factor for the perturbed attention guidance. If it is set to 0.0, the perturbed attention
        guidance will not be used.
    pag_adaptive_scale (`float`, *optional*, defaults to 0.0):
        The adaptive scale factor for the perturbed attention guidance. If it is set to 0.0, `pag_scale` is
        used.
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
      @       zInvalid sample size)ratiosNr   r   g      ?)	rN   rO   r"   rP   rQ   rR   rS   rT   rU   )dim)r>   rM   )
resolutionaspect_ratio)totalmpsnpurb   F)encoder_hidden_statesencoder_attention_masktimestepadded_cond_kwargsr   r   r   orderlatent)r   )r   )images)Cr=   rF   sample_sizerA   r   r   r   r   r'   rH   classify_height_width_binr   
_pag_scale_pag_adaptive_scalerq   rr   r   r/   rh   re   r}   do_perturbed_attention_guidance%_prepare_perturbed_attention_guidanceri   catr5   r0   in_channelsr   rc   attn_processors_set_pag_attn_processorr>   r   maxr   progress_bar	enumeratescale_model_input	is_tensorr"   r   floatfloat32float64int32int64tensorrn   expand#_apply_perturbed_attention_guidancechunkout_channelsr   updaterE   XLA_AVAILABLExm	mark_stepr<   decodescaling_factorresize_and_crop_tensorpostprocessmaybe_free_model_hooksset_attn_processorr   )2rJ   rL   rN   r!   r#   r$   r   rO   r   r   r   r   r   rP   rR   rQ   rS   r   r   r   r   rT   r   rU   r   r   aspect_ratio_binorig_height
orig_widthr   r"   rM   latent_channelsoriginal_attn_procr   r   num_warmup_stepsr   ir   latent_model_inputcurrent_timestepis_mpsis_npurc   
noise_prednoise_pred_uncondnoise_pred_textstep_idximages2                                                     r4   __call__PixArtSigmaPAGPipeline.__call__>  s   j V4++22>>AVAVVT))00<<t?T?TT!&&22c9#8 !!((44;#8 !!((44:#7 !!((44:#7  !677&,K 00JJ6aqJrMF"!*
	
 $#5  *VS"9"9JJvt$<$<VJ&,,Q/J''
 '5s&:# '+"7'#9"7+I' 3  
	
!"* // FF7RM %)$N$N%'EGb%! )!II'=&MSTUM$)II/MOd.ekl$m! *<NN/*
&	
 **11==&&..	
 //!%!1!1!A!A((#'#:#:,G )  !::9J ,0F s9~0CnnFZFZ0ZZ\]^%89\!),1%*YYyM<O<OPQ<RV]VcVcdeVf<f/g%h"%)^^%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 % .  
 77!%!I!I"$?Qa"J 19C9I9I!9L6%!2^YjGj5k!kJ ##**771<O!+!1!1!!1!;A!>J!+J ..--j!WmHYmglmnop I**A9I/IqSTuX\XfXfXlXlNlpqNq '')+N0Ba0G#$(K#K 1g6 =LLNs - :x h&HHOOGhhoo.L.L$LZ_O`abcE%,,CCE:WbcEh&((44U4TE 	##%////0BC8O"%00_ :9s   K(\49\44
])r   r   rH   rA   )zblocks.1)
Tr   r   NNNNNF,  NNNN)Fr   )Nr      NNg      @r   NN        NNNNNNpilTNr   TTr  g      @r  )*__name__
__module____qualname____firstlineno____doc__r   r   r   _optional_componentsmodel_cpu_offload_seqr	   r   r   r   r   r   rr   r   rC   boolr   r   ri   r"   Tensorr}   r   r   rf   r   r   no_gradr   EXAMPLE_DOC_STRINGr   	Generatorr   r   r   r  __static_attributes____classcell__)r.   s   @r4   r8   r8      s   
 jj	O  (8< 5?88 %8 	8
 .8 -8 "#tCy.18 80 -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!2 #"'+AH*2pf, ]]_12 )-!#%#" #/0 $#MQ*.048<9=AE%* GK"'+#&$'5n1c49n%n1 n1 !	n1
 9n1 Un1 n1  (}n1 n1 }n1 n1 E%//43H"HIJn1 %,,'n1  -n1  (5n1  !) 6!n1" )1(>#n1$ c]%n1& 'n1( 8S#u||$<d$BCD)n1* +n1, -n1. !%/n10 !1n12 3n14 "5n16 
"E)	*7n1 3 n1r6   r8   r  )>r   r)   r   urllib.parseparser   typingr   r   r   r   r   ri   transformersr   r	   rH   r   modelsr   r   
schedulersr   utilsr   r   r   r   r   r   r   utils.torch_utilsr   pipeline_utilsr   r   "pixart_alpha.pipeline_pixart_alphar   r   r   "pixart_alpha.pipeline_pixart_sigmar   	pag_utilsr   torch_xla.core.xla_modelcore	xla_modelr   r   
get_loggerr  rl   r   r    r   r  r   rr   r"   r   r5   r8   r&   r6   r4   <module>r0     s     	  9 9  4 3 = 3   . C 
 G  ))MM			H	% ! . *.15%)$(8*!#8* U3,-.8* S	"	8*
 T%[!8*v^1. ^1r6   