
    +h>                         S SK JrJr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  S	S
KJrJrJr  \" 5       (       a  S SKJs  Jr  SrOSrSr " S S\\5      r g)    )AnyCallableDictListOptionalTupleUnionN)CLIPTextModelWithProjectionCLIPTokenizer   )VaeImageProcessor)UVit2DModelVQModel)AmusedScheduler)is_torch_xla_availablereplace_example_docstring   )DeprecatedPipelineMixinDiffusionPipelineImagePipelineOutputTFa{  
    Examples:
        ```py
        >>> import torch
        >>> from diffusers import AmusedPipeline

        >>> pipe = AmusedPipeline.from_pretrained("amused/amused-512", variant="fp16", torch_dtype=torch.float16)
        >>> pipe = pipe.to("cuda")

        >>> prompt = "a photo of an astronaut riding a horse on mars"
        >>> image = pipe(prompt).images[0]
        ```
c            /         ^  \ rS rSr% Sr\\S'   \\S'   \\S'   \	\S'   \
\S'   \\S'   S	rS\S\S\	S\
S\4
U 4S
 jjr\R                  " 5       \" \5                           S"S\\\\   \4      S\\   S\\   S\S\S\\\\\   4      S\\   S\\R0                     S\\R2                     S\\R4                     S\\R4                     S\\R4                     S\\R4                     S\S\\\\\R4                  /S4      S\S\\\\4      S\S\\\4   S\\\\\4   \\   4   4(S  jj5       5       r S!r!U =r"$ )#AmusedPipeline2   z0.33.1image_processorvqvae	tokenizertext_encodertransformer	schedulerz text_encoder->transformer->vqvaec                 
  > [         TU ]  5         U R                  UUUUUS9  [        U SS 5      (       a/  S[	        U R
                  R                  R                  5      S-
  -  OSU l        [        U R                  SS9U l
        g )N)r   r   r   r   r   r   r         F)vae_scale_factordo_normalize)super__init__register_modulesgetattrlenr   configblock_out_channelsr#   r   r   )selfr   r   r   r   r   	__class__s         d/home/james-whalen/.local/lib/python3.13/site-packages/diffusers/pipelines/amused/pipeline_amused.pyr&   AmusedPipeline.__init__=   s     	%# 	 	
 ELDRY[_D`D`A#djj''::;a?@fg 	  1$BWBWfkl    Npromptheightwidthnum_inference_stepsguidance_scalenegative_promptnum_images_per_prompt	generatorlatentsprompt_embedsencoder_hidden_statesnegative_prompt_embedsnegative_encoder_hidden_statesreturn_dictcallbackcallback_stepscross_attention_kwargs"micro_conditioning_aesthetic_scoremicro_conditioning_crop_coordtemperaturec           
         U
b  Ub  U
c  Ub  [        S5      eUb  Ub  Uc  Ub  [        S5      eUc  U
b  Ub  U
b  [        S5      e[        U[        5      (       a  U/nUb  [        U5      nOU
R                  S   nUU-  nUc-  U R
                  R                  R                  U R                  -  nUc-  U R
                  R                  R                  U R                  -  nU
cv  U R                  USSSU R                  R                  S	9R                  R                  U R                  5      nU R                  USSS
9nUR                  n
UR                   S   nU
R#                  US5      n
UR#                  USS5      nUS:  a  Uc  Uc  S/[        U5      -  n[        U[        5      (       a  U/nU R                  USSSU R                  R                  S	9R                  R                  U R                  5      nU R                  USSS
9nUR                  nUR                   S   nUR#                  US5      nUR#                  USS5      n[$        R&                  " X/5      n
[$        R&                  " X/5      n[$        R(                  " UUUS   US   U/U R                  UR*                  S9nUR-                  S5      nUR/                  US:  a  SU-  OUS5      nUX R                  -  X0R                  -  4nU	cM  [$        R0                  " UU R2                  R                  R4                  [$        R6                  U R                  S9n	U R2                  R9                  UUU R                  5        [        U R2                  R:                  5      X@R2                  R<                  -  -
  nU R?                  US9 n[A        U R2                  R:                  5       GH:  u  nnUS:  a  [$        RB                  " U	/S-  5      nOU	nU R                  UUU
UUS9n US:  a  U RE                  S5      u  n!n"U!UU"U!-
  -  -   n U R2                  RG                  U UU	US9RH                  n	U[        U R2                  R:                  5      S-
  :X  d)  US-   U:  a`  US-   U R2                  R<                  -  S:X  a@  URK                  5         Ub-  UU-  S:X  a$  U[M        U R2                  SS5      -  n#U" U#UU	5        [N        (       d  GM%  [P        RR                  " 5         GM=     SSS5        US:X  a  U	n$GOU RT                  R*                  [$        RV                  :H  =(       a     U RT                  R                  RX                  n%U%(       a  U RT                  R[                  5         U RT                  R]                  U	SUX R                  -  X0R                  -  U RT                  R                  R^                  4S9R`                  Rc                  SS5      n$U Rd                  Rg                  U$U5      n$U%(       a  U RT                  Ri                  5         U Rk                  5         U(       d  U$4$ [m        U$5      $ ! , (       d  f       GNY= f)aw  
The call function to the pipeline for generation.

Args:
    prompt (`str` or `List[str]`, *optional*):
        The prompt or prompts to guide image generation. If not defined, you need to pass `prompt_embeds`.
    height (`int`, *optional*, defaults to `self.transformer.config.sample_size * self.vae_scale_factor`):
        The height in pixels of the generated image.
    width (`int`, *optional*, defaults to `self.unet.config.sample_size * self.vae_scale_factor`):
        The width in pixels of the generated image.
    num_inference_steps (`int`, *optional*, defaults to 16):
        The number of denoising steps. More denoising steps usually lead to a higher quality image at the
        expense of slower inference.
    guidance_scale (`float`, *optional*, defaults to 10.0):
        A higher guidance scale value encourages the model to generate images closely linked to the text
        `prompt` at the expense of lower image quality. Guidance scale is enabled when `guidance_scale > 1`.
    negative_prompt (`str` or `List[str]`, *optional*):
        The prompt or prompts to guide what to not include in image generation. If not defined, you need to
        pass `negative_prompt_embeds` instead. Ignored when not using guidance (`guidance_scale < 1`).
    num_images_per_prompt (`int`, *optional*, defaults to 1):
        The number of images to generate per prompt.
    generator (`torch.Generator`, *optional*):
        A [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) to make
        generation deterministic.
    latents (`torch.IntTensor`, *optional*):
        Pre-generated tokens representing latent vectors in `self.vqvae`, to be used as inputs for image
        generation. If not provided, the starting latents will be completely masked.
    prompt_embeds (`torch.Tensor`, *optional*):
        Pre-generated text embeddings. Can be used to easily tweak text inputs (prompt weighting). If not
        provided, text embeddings are generated from the `prompt` input argument. A single vector from the
        pooled and projected final hidden states.
    encoder_hidden_states (`torch.Tensor`, *optional*):
        Pre-generated penultimate hidden states from the text encoder providing additional text conditioning.
    negative_prompt_embeds (`torch.Tensor`, *optional*):
        Pre-generated negative text embeddings. Can be used to easily tweak text inputs (prompt weighting). If
        not provided, `negative_prompt_embeds` are generated from the `negative_prompt` input argument.
    negative_encoder_hidden_states (`torch.Tensor`, *optional*):
        Analogous to `encoder_hidden_states` for the positive prompt.
    output_type (`str`, *optional*, defaults to `"pil"`):
        The output format of the generated image. Choose between `PIL.Image` or `np.array`.
    return_dict (`bool`, *optional*, defaults to `True`):
        Whether or not to return a [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] instead of a
        plain tuple.
    callback (`Callable`, *optional*):
        A function that calls every `callback_steps` steps during inference. The function is 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 is called. If not specified, the callback is called at
        every step.
    cross_attention_kwargs (`dict`, *optional*):
        A kwargs dictionary that if specified is passed along to the [`AttentionProcessor`] as defined in
        [`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
    micro_conditioning_aesthetic_score (`int`, *optional*, defaults to 6):
        The targeted aesthetic score according to the laion aesthetic classifier. See
        https://laion.ai/blog/laion-aesthetics/ and the micro-conditioning section of
        https://huggingface.co/papers/2307.01952.
    micro_conditioning_crop_coord (`Tuple[int]`, *optional*, defaults to (0, 0)):
        The targeted height, width crop coordinates. See the micro-conditioning section of
        https://huggingface.co/papers/2307.01952.
    temperature (`Union[int, Tuple[int, int], List[int]]`, *optional*, defaults to (2, 0)):
        Configures the temperature scheduler on `self.scheduler` see `AmusedScheduler#set_timesteps`.

Examples:

Returns:
    [`~pipelines.pipeline_utils.ImagePipelineOutput`] or `tuple`:
        If `return_dict` is `True`, [`~pipelines.pipeline_utils.ImagePipelineOutput`] is returned, otherwise a
        `tuple` is returned where the first element is a list with the generated images.
NzGpass either both `prompt_embeds` and `encoder_hidden_states` or neitherzXpass either both `negatve_prompt_embeds` and `negative_encoder_hidden_states` or neitherz,pass only one of `prompt` or `prompt_embeds`r   pt
max_lengthT)return_tensorspadding
truncationrG   )r>   output_hidden_statesr!   g      ? )devicedtyper   )rO   rN   )total)micro_condspooled_text_embr;   rA   )model_outputtimestepsampler8   orderlatent)force_not_quantizeshape)7
ValueError
isinstancestrr)   rZ   r   r*   sample_sizer#   r   model_max_length	input_idsto_execution_devicer   text_embedshidden_statesrepeattorchconcattensorrO   	unsqueezeexpandfullr   mask_token_idlongset_timesteps	timestepsrW   progress_bar	enumeratecatchunkstepprev_sampleupdater(   XLA_AVAILABLExm	mark_stepr   float16force_upcastfloatdecodelatent_channelsrV   clipr   postprocesshalfmaybe_free_model_hooksr   )&r,   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   output_typer>   r?   r@   rA   rB   rC   rD   
batch_sizer`   outputsrR   rZ   num_warmup_stepsrp   irU   model_inputrT   uncond_logitscond_logitsstep_idxoutputneeds_upcastings&                                         r.   __call__AmusedPipeline.__call__S   sH   ~ %*?*G!&;&Gfgg".3Q3Y"*/M/Yj  N}4&:LQ^QjKLLfc""XFVJ&,,Q/J"77
>%%,,884;P;PPF=$$++77$:O:OOE #$>>:: '  i4112  ''	tZ^'_G#//M$+$9$9"$=!%,,-BAF 5 < <=RTUWX YC%-"*')dS[&8Oos33'6&7O NN##'(##~~>> +  )BBt556  ++I4^b+c)0)<)<&181F1Fr1J.%;%B%BCXZ[%\"-K-R-RShjkmn-o*!LL*@)PQM$)LL2P1h$i! ll-a0-a02 ))'--

 "++A.!((>C;OZU_acdV'<'<<eG\G\>\]?jjt~~,,::%**UYUkUkG 	$$%8+tG]G]^t~~778;NQ_Q_QeQe;ee%89\()A)AB8!C'"'))WIM":K")K#// +$1*?+A  0   "C'1=1C1CA1F.M;#0>[S`E`3a#aL..--!-%"'	 . 
 +  DNN44599U..AET^^=Q=Q3QUV3V '')+N0Ba0G#$(K#K 8W= =LLNE  C :J ("F"jj..%--?bDJJDUDUDbDbO

  "ZZ&&#'333222JJ%%55	 ' 	 fTT!QZ  ))55fkJF

!##%9"6**C :9s   9E Y*>Y**
Y9)r   r#   )NNN   g      $@Nr!   NNNNNNpilTNr!   N   )r   r   )r   r   )#__name__
__module____qualname____firstlineno___last_supported_versionr   __annotations__r   r   r
   r   r   model_cpu_offload_seqr&   rf   no_gradr   EXAMPLE_DOC_STRINGr   r	   r   r]   intr|   	Generator	IntTensorTensorboolr   r   r   r   r   __static_attributes____classcell__)r-   s   @r.   r   r   2   s_   &&&N-->mm !m 2	m
 !m #m, ]]_12 37 $##% $;?/0/3-1048<9=AE GK;?239?>D-A+tCy#~./A+ A+ }	A+
 !A+ A+ "%T#Y"78A+  (}A+ EOO,A+ %//*A+  -A+  (5A+ !) 6A+ )1(>A+  !A+" 8S#u||$<d$BCD#A+$ %A+& !)c3h 8'A+( -0)A+* (-S#X+A+, 3c3hc:;-A+ 3 A+r0   r   )!typingr   r   r   r   r   r   r	   rf   transformersr
   r   r   r   modelsr   r   
schedulersr   utilsr   r   pipeline_utilsr   r   r   torch_xla.core.xla_modelcore	xla_modelrx   rw   r   r    r0   r.   <module>r      s^    E D D  C 0 * ) F \ \ ))MM d+,.? d+r0   