o
    ۷i                     @   sP   d dl Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 G dd	 d	eZ
dS )
    N   )UNet2DModel)PNDMScheduler)randn_tensor   )DiffusionPipelineImagePipelineOutputc                       s   e Zd ZU dZeed< eed< dedef fddZe	 						
dde
de
dejeej B dB dedB dedeeB fddZ  ZS )PNDMPipelinea  
    Pipeline for unconditional 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 ([`PNDMScheduler`]):
            A `PNDMScheduler` to be used in combination with `unet` to denoise the encoded image.
    unet	schedulerc                    s(   t    t|j}| j||d d S )N)r
   r   )super__init__r   from_configconfigregister_modules)selfr
   r   	__class__ g/home/ubuntu/vllm_env/lib/python3.10/site-packages/diffusers/pipelines/deprecated/pndm/pipeline_pndm.pyr   )   s   
zPNDMPipeline.__init__   2   NpilT
batch_sizenum_inference_steps	generatoroutput_typereturn_dictreturnc           
      K   s   t || jjj| jjj| jjjf|| jd}| j| | | jj	D ]}| ||j
}	| j|	||j}q"|d d dd}| dddd }|dkrT| |}|sY|fS t|dS )	aX  
        The call function to the pipeline for generation.

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

        Example:

        ```py
        >>> from diffusers import PNDMPipeline

        >>> # load model and scheduler
        >>> pndm = PNDMPipeline.from_pretrained("google/ddpm-cifar10-32")

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

        >>> # save image
        >>> image.save("pndm_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.
        )r   device   g      ?r   r   r   r   )images)r   r
   r   in_channelssample_sizer   r   set_timestepsprogress_bar	timestepssamplestepprev_sampleclampcpupermutenumpynumpy_to_pilr   )
r   r   r   r   r   r   kwargsimagetmodel_outputr   r   r   __call__0   s    3

zPNDMPipeline.__call__)r   r   Nr   T)__name__
__module____qualname____doc__r   __annotations__r   r   torchno_gradint	Generatorliststrboolr   tupler3   __classcell__r   r   r   r   r	      s0   
 r	   )r9   modelsr   
schedulersr   utils.torch_utilsr   pipeline_utilsr   r   r	   r   r   r   r   <module>   s   