
    +h                         S SK JrJrJrJr  S SKrSSKJr  SSKJ	r	  SSK
Jr  SSKJr  SS	KJrJr  \" 5       (       a  S SKJs  Jr  S
rOSr " S S\5      rg)    )ListOptionalTupleUnionN   )UNet2DModel)DDPMScheduler)is_torch_xla_available)randn_tensor   )DiffusionPipelineImagePipelineOutputTFc                      ^  \ rS rSrSrSrS\S\4U 4S jjr\	R                  " 5            SS\S\\\	R                  \\	R                     4      S\S	\\   S
\S\\\4   4S jj5       rSrU =r$ )DDPMPipeline#   a	  
Pipeline for image generation.

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

Parameters:
    unet ([`UNet2DModel`]):
        A `UNet2DModel` to denoise the encoded image latents.
    scheduler ([`SchedulerMixin`]):
        A scheduler to be used in combination with `unet` to denoise the encoded image. Can be one of
        [`DDPMScheduler`], or [`DDIMScheduler`].
unet	schedulerc                 @   > [         TU ]  5         U R                  XS9  g )N)r   r   )super__init__register_modules)selfr   r   	__class__s      `/home/james-whalen/.local/lib/python3.13/site-packages/diffusers/pipelines/ddpm/pipeline_ddpm.pyr   DDPMPipeline.__init__4   s    4=    
batch_size	generatornum_inference_stepsoutput_typereturn_dictreturnc                    [        U R                  R                  R                  [        5      (       aa  UU R                  R                  R
                  U R                  R                  R                  U R                  R                  R                  4nOBXR                  R                  R
                  /U R                  R                  R                  Q7nU R                  R                  S:X  a:  [        XbU R                  R                  S9nUR                  U R                  5      nO)[        XbU R                  U R                  R                  S9nU R                  R                  U5        U R                  U R                  R                  5       Hd  nU R                  Xx5      R                  n	U R                  R!                  XXrS9R"                  n[$        (       d  MO  [&        R(                  " 5         Mf     US-  S-   R+                  SS5      nUR-                  5       R/                  SSS	S5      R1                  5       nUS
:X  a  U R3                  U5      nU(       d  U4$ [5        US9$ )ay  
The call function to the pipeline for generation.

Args:
    batch_size (`int`, *optional*, defaults to 1):
        The number of images to generate.
    generator (`torch.Generator`, *optional*):
        A [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) to make
        generation deterministic.
    num_inference_steps (`int`, *optional*, defaults to 1000):
        The number of denoising steps. More denoising steps usually lead to a higher quality image at the
        expense of slower inference.
    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.ImagePipelineOutput`] instead of a plain tuple.

Example:

```py
>>> from diffusers import DDPMPipeline

>>> # load model and scheduler
>>> pipe = DDPMPipeline.from_pretrained("google/ddpm-cat-256")

>>> # run pipeline in inference (sample random noise and denoise)
>>> image = pipe().images[0]

>>> # save image
>>> image.save("ddpm_generated_image.png")
```

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
mps)r   dtype)r   devicer%   )r   r   g      ?r      r   pil)images)
isinstancer   configsample_sizeintin_channelsr&   typer   r%   tor   set_timestepsprogress_bar	timestepssamplestepprev_sampleXLA_AVAILABLExm	mark_stepclampcpupermutenumpynumpy_to_pilr   )
r   r   r   r   r    r!   image_shapeimagetmodel_outputs
             r   __call__DDPMPipeline.__call__8   s   ^ dii&&22C88		  ,,		  ,,		  ,,	K &yy'7'7'C'CcdiiFVFVFbFbcK;;u$ YEHHT[[)E $++]a]f]f]l]lmE 	$$%89""4>>#;#;<A99U.55L NN'''T``E} = S''1-		##Aq!Q/557%%%e,E8O"%00r    )r'   Ni  r(   T)__name__
__module____qualname____firstlineno____doc__model_cpu_offload_seqr   r	   r   torchno_gradr-   r   r   	Generatorr   strboolr   r   rC   __static_attributes____classcell__)r   s   @r   r   r   #   s     #>[ >] > ]]_ MQ#'%* T1T1 E%//43H"HIJT1 !	T1
 c]T1 T1 
"E)	*T1 T1r   r   )typingr   r   r   r   rL   modelsr   
schedulersr	   utilsr
   utils.torch_utilsr   pipeline_utilsr   r   torch_xla.core.xla_modelcore	xla_modelr8   r7   r   rE   r   r   <module>r\      sI     0 /  ! ' + - C ))MMj1$ j1r   