
    +hr                     |   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'  \" 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K2r20 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/_S1S2S3/_S4S2S5/_S6S7S5/_0 S8S7S9/_S:S;S9/_S<S;S=/_S>S=S=/_S?S=S;/_S@S9S;/_SAS9S7/_SBS5S7/_SCS5S2/_SDS3S2/_SES0S./_SFS,S./_SGS*S'/_SHS(S'/_SIS%S"/_SJS#S"/_SKS S/_ESS/SS/SS/SS/SS/SS/SL.Er3SMr4    SUSN\	\5   SO\	\\6\Rn                  4      SP\	\\5      SQ\	\\8      4SR jjr9 " SS ST\"5      r:g)V    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_BINTF)BeautifulSoupz0.25g      @g      @z0.26g      @z0.27g      @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2.89)z3.0z3.11z3.62z3.75z3.88z4.0aH  
    Examples:
        ```py
        >>> import torch
        >>> from diffusers import PixArtSigmaPipeline

        >>> # You can replace the checkpoint id with "PixArt-alpha/PixArt-Sigma-XL-2-512-MS" too.
        >>> pipe = PixArtSigmaPipeline.from_pretrained(
        ...     "PixArt-alpha/PixArt-Sigma-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]
        ```
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_sigma.pyretrieve_timestepsr3   ~   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PixArtSigmaPipeline   ad  
Pipeline for text-to-image generation using PixArt-Sigma.

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-Sigma-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)r8   r9   r:   r;   r.   r:   r   r      )vae_scale_factor)super__init__register_modulesgetattrr-   r:   configblock_out_channelsr>   r   image_processor)selfr8   r9   r:   r;   r.   r,   s         r2   r@   PixArtSigmaPipeline.__init__   s|     	hq 	 	
 W^^bdikoVpVpc$((//*L*L&MPQ&Q Rvw3TEZEZ[r4   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_preprocessingr8   	input_idsshapetorchequalbatch_decodeloggerwarningr]   tor9   r_   r;   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                            r2   encode_prompt!PixArtSigmaPipeline.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kr4   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         r2   prepare_extra_step_kwargs-PixArtSigmaPipeline.prepare_extra_step_kwargs  s     s7#4#4T^^5H5H#I#T#T#Y#Y#[\\'*e$ (3w/@/@ATAT/U/`/`/e/e/g+hh-6k*  r4   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
             r2   check_inputs PixArtSigmaPipeline.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$r4   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    r2   process8PixArtSigmaPipeline._text_preprocessing.<locals>.process  sH    **40**40 K zz|))+Kr4   )
r   rh   ri   r   formatr   rm   tupler   rn   )rF   r   rP   r   ts   ` `  r2   rb   'PixArtSigmaPipeline._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      r2   r   "PixArtSigmaPipeline._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}}r4   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
             r2   prepare_latents#PixArtSigmaPipeline.prepare_latentsa  s     K4000J$///	
 i&&3y>Z+GA#i.AQ R&<'gi 
 ?"5fZGjj(G NN;;;r4   r   r!   r"   guidance_scaler   r   r|   r}   r   output_typereturn_dictcallbackr   use_resolution_binning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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![7        [        U5      X0R,                  R8                  -  -
  S	5      n"U R;                  US9 n#[=        U5       GH  u  n$n%U(       a  [&        R(                  " U/S-  5      OUn&U R,                  R?                  U&U%5      n&U%n'[&        R@                  " U'5      (       d  U&RB                  RD                  S:H  n(U&RB                  RD                  S:H  n)[        U'[F        5      (       a/  U((       d  U)(       a  [&        RH                  O[&        RJ                  n*O.U((       d  U)(       a  [&        RL                  O[&        RN                  n*[&        RP                  " U'/U*U&RB                  S9n'O7[        U'R                   5      S	:X  a  U'S   RS                  U&RB                  5      n'U'RU                  U&R                   S	   5      n'U R                  U&UUU'U!SS9S	   n+U(       a  U+RW                  S5      u  n,n-U,UU-U,-
  -  -   n+U R                   R                  RX                  S-  U:X  a  U+RW                  SSS9S	   n+OU+n+U R,                  RZ                  " 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,                  R8                  -  S	:X  a@  U#R]                  5         Ub-  U$U-  S	:X  a$  U$[_        U R,                  SS5      -  n.U" U.U%U5        [`        (       d  GM  [b        Rd                  " 5         GM     SSS5        US:X  d  U Rf                  Ri                  URS                  U Rf                  R2                  5      U Rf                  R                  Rj                  -  SS9S	   n/U(       a  U R                  Rm                  U/WW5      n/OUn/US:X  d  U R                  Ro                  U/US9n/U Rq                  5         U(       d  U/4$ [s        U/S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-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`.

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)
resolutionaspect_ratio)totalr   mpsnpur^   F)encoder_hidden_statesencoder_attention_masktimestepadded_cond_kwargsr   r   orderlatent)r   )r   )images):r;   rC   sample_sizer>   ASPECT_RATIO_2048_BINr   r   r   r%   rE   classify_height_width_binr   rm   rn   r   r-   rd   ra   ry   re   catr3   r.   in_channelsr   r_   r   maxr   progress_bar	enumeratescale_model_input	is_tensorr    r   floatfloat32float64int32int64tensorrj   expandchunkout_channelsr~   updaterB   XLA_AVAILABLExm	mark_stepr:   decodescaling_factorresize_and_crop_tensorpostprocessmaybe_free_model_hooksr   )0rF   rH   rJ   r   r!   r"   r   rK   r   r   r|   r}   r   rL   rN   rM   rO   r   r   r   r   rP   r   rQ   r/   aspect_ratio_binorig_height
orig_widthr   r    rI   latent_channelsr   r   num_warmup_stepsr   ir   latent_model_inputcurrent_timestepis_mpsis_npur_   
noise_prednoise_pred_uncondnoise_pred_textstep_idximages0                                                   r2   __call__PixArtSigmaPipeline.__call__w  s   ^ 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"!*
	
 *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 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 ..--j!WmHYmglmnop I**A9I/IqSTuX\XfXfXlXlNlpqNq '')+N0Ba0G#$(K#K 1g6 =LLNi - :n h&HHOOGJJtxx~~$>A_A_$_mrOstuvE%,,CCE:WbcEh&((44U4TE 	##%8O"%00O :9s   J.Y,9Y,,
Y:)rE   r>   )
Tr   r   NNNNNF,  NNNN)Fr   )Nr      NNg      @r   NNg        NNNNNNpilTNr   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   @r2   r6   r6      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!2 #"'+AH*2pf, ]]_12 )-!#%#" #/0 $#MQ*.048<9=AE%* GK"'+#&1Q1c49n%Q1 Q1 !	Q1
 9Q1 UQ1 Q1  (}Q1 Q1 }Q1 Q1 E%//43H"HIJQ1 %,,'Q1  -Q1  (5Q1  !) 6!Q1" )1(>#Q1$ c]%Q1& 'Q1( 8S#u||$<d$BCD)Q1* +Q1, -Q1. !%/Q10 !1Q14 
"E)	*5Q1 3 Q1r4   r6   r   );r   r'   r   urllib.parseparser   typingr   r   r   r   r   re   transformersr   r	   rE   r   modelsr   r   
schedulersr   utilsr   r   r   r   r   r   r   utils.torch_utilsr   pipeline_utilsr   r   pipeline_pixart_alphar   r   r   torch_xla.core.xla_modelcore	xla_modelr   r   
get_loggerr  rh   r   r   r   r   r  r   rn   r    r   r3   r6   r$   r4   r2   <module>r     s     	  9 9  4 3 = 3   . C  ))MM			H	% !)
VV)
VV) VV) VV	)
 VV) VV) VV) 
FF) VV) VV) 
FF) VV) VV) 
FF) VV)  VV!)" VV#)$ VV%)& VV')( VV))* 
FF+), VV-). VV/)0 VV1)2 VV3)4 VV5)6 VV7)8 VV9): VV;)< 
FF=)> VV?)@ 
FFA)B 
FFC)D VVE)F FVVVVFQ) X , *.15%)$(8*!#8* U3,-.8* S	"	8*
 T%[!8*vQ1+ Q1r4   