
    
3js              
          S SK r S SKrS SKrS SKJr  S SK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r,OSr,\RZ                  " \.5      r/\" 5       (       a  S SK0J1r1  \" 5       (       a  S SK2r2Sr3    SS\4S-  S\5\Rl                  -  S-  S\7\4   S-  S\7\8   S-  4S jjr9 " S S\\'5      r:g)    N)Callable)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/wildlama/miniconda3/lib/python3.13/site-packages/diffusers/pipelines/pag/pipeline_pag_pixart_sigma.pyretrieve_timestepsr1   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            8         ^  \ rS rSrSr\R                  " S5      rSS/rSr	 S1S\
S\S\S\S	\S
\\\   -  4U 4S jjjr          S2S\\\   -  S\S\S\S\R*                  S-  S\R,                  S-  S\R,                  S-  S\R,                  S-  S\R,                  S-  S\S\4S jjrS r    S3S jrS4S jrS rS5S jr\R:                  " 5       \" \5                               S6S\\\   -  S\S\S\\   S \\    S!\ S\S-  S"\S-  S#\S-  S$\ S%\RB                  \\RB                     -  S-  S&\R,                  S-  S\R,                  S-  S\R,                  S-  S\R,                  S-  S\R,                  S-  S'\S-  S(\S)\"\\\R,                  /S4   S-  S*\S\S+\S\S,\ S-\ S.\#\$-  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transformerr,   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)r6   r7   r8   r9   r,   r8   r   r      )vae_scale_factor)super__init__register_modulesgetattrr+   r8   configblock_out_channelsr=   r   image_processorset_pag_applied_layers)selfr6   r7   r8   r9   r,   r:   r*   s          r0   r?   PixArtSigmaPAGPipeline.__init__   s     	hq 	 	
 W^^bdikoVpVpc$((//*L*L&MPQ&Q Rvw3TEZEZ[##$67r2   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)rP   
max_lengthTpt)paddingrU   
truncationadd_special_tokensreturn_tensorslongest)rW   rZ   r   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_preprocessingr6   	input_idsshapetorchequalbatch_decodeloggerwarningr]   tor7   r_   r9   repeatview
isinstancestr)rF   rH   rI   rJ   rK   r   rL   rM   rN   rO   rP   rQ   r-   deprecation_messagerU   text_inputstext_input_idsuntruncated_idsremoved_textr_   bs_embedseq_len_uncond_tokensuncond_inputs                            r0   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kr2   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)   )rF   r}   r|   accepts_etaextra_step_kwargsaccepts_generators         r0   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*  r2   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   )
rF   rH   heightwidthrJ   callback_stepsrL   rM   rN   rO   s
             r0   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$r2   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   rP   rF   s    r0   process;PixArtSigmaPAGPipeline._text_preprocessing.<locals>.process  sH    **40**40 K zz|))+Kr2   )
r   rh   ri   r   formatr   rm   tupler   rn   )rF   r   rP   r   ts   ` `  r0   rb   *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+$)rn   ulunquote_plusr   r   resubr   r   bad_punct_regexcompiler+   findallr   fix_texthtmlunescape)rF   captionregex2s      r0   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}}r2   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)
rF   
batch_sizenum_channels_latentsr   r   r_   r   r}   latentsrd   s
             r0   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;;;r2   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[2        (       a  Sn OUn [5        U R6                  UU XE5      u  pCU R                   R                  R8                  n!U R;                  UU-  U!UU	UR<                  UUU5      nU R*                  (       a0  U R                   R>                  n"U RA                  U RB                  US9  U RE                  X5      n#SSS.n$[G        [#        U5      X0R6                  RH                  -  -
  S	5      n%U RK                  US9 n&[M        U5       GH  u  n'n([.        R0                  " U/UR$                  S	   UR$                  S	   -  -  5      n)U R6                  RO                  U)U(5      n)U(n*[.        RP                  " U*5      (       d  U)RR                  RT                  S:H  n+U)RR                  RT                  S:H  n,[        U*[V        5      (       a/  U+(       d  U,(       a  [.        RX                  O[.        RZ                  n-O.U+(       d  U,(       a  [.        R\                  O[.        R^                  n-[.        R`                  " U*/U-U)RR                  S9n*O7[#        U*R$                  5      S	:X  a  U*S   Rc                  U)RR                  5      n*U*Re                  U)R$                  S	   5      n*U R                  U)UUU*U$SS9S	   n.U R*                  (       a  U Rg                  U.UUU*5      n.O&U(       a  U.Ri                  S5      u  n/n0U/UU0U/-
  -  -   n.U R                   R                  Rj                  S-  U!:X  a  U.Ri                  SSS9S	   n.OU.n.U R6                  Rl                  " 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 R6                  RH                  -  S	:X  a@  U&Ro                  5         Ub-  U'U-  S	:X  a$  U'[q        U R6                  SS5      -  n1U" U1U(U5        [2        (       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	   n2U(       a  U R                  R}                  U2WW5      n2OUn2US:X  d  U R                  R                  U2US9n2U R                  5         U R*                  (       a  U R                   R                  W"5        U(       d  U24$ [        U2S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 be 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      ?)	rJ   rK   r   rL   rM   rN   rO   rP   rQ   )dimcpu)r:   rI   )
resolutionaspect_ratio)totalmpsnpur^   F)encoder_hidden_statesencoder_attention_masktimestepadded_cond_kwargsr   r   r   orderlatent)r   )r   )images)Cr9   rB   sample_sizer=   r   r   r   r   r#   rD   classify_height_width_binr   
_pag_scale_pag_adaptive_scalerm   rn   r   r+   rd   ra   ry   do_perturbed_attention_guidance%_prepare_perturbed_attention_guidancere   catXLA_AVAILABLEr1   r,   in_channelsr   r_   attn_processors_set_pag_attn_processorr:   r   maxr   progress_bar	enumeratescale_model_input	is_tensorr   r   floatfloat32float64int32int64tensorrj   expand#_apply_perturbed_attention_guidancechunkout_channelsr~   updaterA   xm	mark_stepr8   decodescaling_factorresize_and_crop_tensorpostprocessmaybe_free_model_hooksset_attn_processorr   )3rF   rH   rJ   r   r   r    r   rK   r   r   r|   r}   r   rL   rN   rM   rO   r   r   r   r   rP   r   rQ   r   r   aspect_ratio_binorig_height
orig_widthr   r   rI   timestep_devicelatent_channelsoriginal_attn_procr   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                                                      r0   __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! =#O$O);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(]	]
])r   r   rD   r=   )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
   rn   r   r?   boolr   re   r   Tensorry   r   r   rb   r   r   no_gradr   EXAMPLE_DOC_STRINGr   	Generatorr   r   r   r	  __static_attributes____classcell__)r*   s   @r0   r4   r4      s   
 jj	O  (8< /988 %8 	8
 .8 -8  $s)O8 80 -1!%&&*-16:59>B##&Eld3iEl &*El 	El
  #El t#El ||d*El !&t 3El  %||d2El ).t(;El El !ElP!2 #"'+AH*2pf, ]]_12 #'!#%#" #,-! DH'+-1596:>B"' DH"'+#&$'5r1d3ir1 r1 !	r1
 9r1 Ur1 r1  #Tzr1 d
r1 Tzr1 r1 ??T%//%::TAr1 $r1 ||d*r1  %||d2r1  !&t 3!r1" ).t(;#r1$ 4Z%r1& 'r1( Cell3T9:TA)r1* +r1, -r1. !%/r10 !1r12 3r14 "5r16 
u	$7r1 3 r1r2   r4   r  );r   r%   r   urllib.parseparser   typingr   re   transformersr   r   rD   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  rh   r   r   r   r  r   rn   r   r   r   r1   r4   r"   r2   r0   <module>r.     s     	    4 3 = 3   . C 
 G  ))MM			H	% ! . '+(,"&!%8*t8* %,,%8* Cy4	8*
 K$8*vb1. b1r2   