
    bi6                     n    d dl mZmZmZmZ 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
e      Zy)    )ListOptionalTupleUnionN   )UNet2DModel)PNDMScheduler)randn_tensor   )DiffusionPipelineImagePipelineOutputc                        e Zd ZU dZeed<   eed<   dedef fdZ ej                         	 	 	 	 	 dde
de
deeej                  eej                     f      dee   d	ed
eeef   fd       Z x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                     t         |           t        j                  |j                        }| j                  ||       y )N)r   r   )super__init__r	   from_configconfigregister_modules)selfr   r   	__class__s      l/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/diffusers/pipelines/deprecated/pndm/pipeline_pndm.pyr   zPNDMPipeline.__init__+   s7    !--i.>.>?	49=    
batch_sizenum_inference_steps	generatoroutput_typereturn_dictreturnc                    t        || j                  j                  j                  | j                  j                  j                  | j                  j                  j                  f|| j
                        }| j                  j                  |       | j                  | j                  j                        D ]E  }| j                  ||      j                  }	| j                  j                  |	||      j                  }G |dz  dz   j                  dd      }|j                         j                  dddd      j!                         }|dk(  r| j#                  |      }|s|fS t%        |      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   pil)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_outputs
             r   __call__zPNDMPipeline.__call__2   s5   f ))55tyy7G7G7S7SUYU^U^UeUeUqUqr;;
 	$$%89""4>>#;#;< 	LA99UA.55LNN''a?KKE	L
 S''1-		##Aq!Q/557%%%e,E8O"%00r   )r%   2   Nr&   T)__name__
__module____qualname____doc__r   __annotations__r	   r   torchno_gradintr   r   	Generatorr   strboolr   r   r9   __classcell__)r   s   @r   r   r      s     >[ >] > U]]_ #%MQ%* F1F1 !F1 E%//43H"HIJ	F1
 c]F1 F1 
"E)	*F1 F1r   r   )typingr   r   r   r   r@   modelsr   
schedulersr	   utils.torch_utilsr
   pipeline_utilsr   r   r    r   r   <module>rM      s+     0 /  " ( . D_1$ _1r   