
    
3j.                         S SK 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  \ R                  " \5      r\" 5       (       a  S SKJs  Jr  S	rOS
r " S S\5      rg)    N   )UNet2DModel)DDIMScheduler)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                     -  S-  S	\S
\S\S-  S\S-  S\S\\-  4S jj5       rSrU =r$ )DDIMPipeline%   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         [        R                  " UR                  5      nU R                  XS9  g )N)r   r   )super__init__r   from_configconfigregister_modules)selfr   r   	__class__s      `/home/wildlama/miniconda3/lib/python3.13/site-packages/diffusers/pipelines/ddim/pipeline_ddim.pyr   DDIMPipeline.__init__6   s7     "--i.>.>?	4=    N
batch_size	generatoretanum_inference_stepsuse_clipped_model_output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SUs=::  a  S::  d  O  [        R                  SU S35        [        U[        5      (       a*  [        U5      U:w  a  [        S[        U5       SU S35      e[        XU R                  U R                  R                  S9n	U R                  R                  U5        U R!                  U R                  R"                  5       He  n
U R                  X5      R$                  nU R                  R'                  XXXRS	9R(                  n	[*        (       d  MP  [,        R.                  " 5         Mg     U	S
-  S-   R1                  SS5      n	U	R3                  5       R5                  SS
SS5      R7                  5       n	US:X  a  U R9                  U	5      n	U(       d  U	4$ [;        U	S9$ )u	  
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.
    eta (`float`, *optional*, defaults to 0.0):
        Corresponds to parameter eta (η) from the [DDIM](https://huggingface.co/papers/2010.02502) paper. Only
        applies to the [`~schedulers.DDIMScheduler`], and is ignored in other schedulers. A value of `0`
        corresponds to DDIM and `1` corresponds to DDPM.
    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.
    use_clipped_model_output (`bool`, *optional*, defaults to `None`):
        If `True` or `False`, see documentation for [`DDIMScheduler.step`]. If `None`, nothing is passed
        downstream to the scheduler (use `None` for schedulers which don't support this argument).
    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 DDIMPipeline
>>> import PIL.Image
>>> import numpy as np

>>> # load model and scheduler
>>> pipe = DDIMPipeline.from_pretrained("fusing/ddim-lsun-bedroom")

>>> # run pipeline in inference (sample random noise and denoise)
>>> image = pipe(eta=0.0, num_inference_steps=50)

>>> # process image to PIL
>>> image_processed = image.cpu().permute(0, 2, 3, 1)
>>> image_processed = (image_processed + 1.0) * 127.5
>>> image_processed = image_processed.numpy().astype(np.uint8)
>>> image_pil = PIL.Image.fromarray(image_processed[0])

>>> # save image
>>> image_pil.save("test.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
        g      ?z:`eta` should be between 0 and 1 (inclusive), but received zy. A value of 0 corresponds to DDIM and 1 corresponds to DDPM. Unexpected results may occur for values outside this range.z/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   devicedtype)r   r   r   r   g      ?r      r   pil)images)
isinstancer   r   sample_sizeintin_channelsloggerwarninglistlen
ValueErrorr   _execution_devicer&   r   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   r    r!   image_shapeimagetmodel_outputs               r   __call__DDIMPipeline.__call__>   s   B dii&&22C88		  ,,		  ,,		  ,,	K &yy'7'7'C'CcdiiFVFVFbFbcKc S NNLSE RN N i&&3y>Z+GA#i.AQ R&<'gi 
 [dF\F\dhdmdmdsdst 	$$%89""4>>#;#;<A99U.55L
 NN''Jb ( k  } = S''1-		##Aq!Q/557%%%e,E8O"%00r    )r'   Nr$   2   Nr(   T)__name__
__module____qualname____firstlineno____doc__model_cpu_offload_seqr   r   r   torchno_gradr,   	Generatorr0   floatboolstrr
   tuplerF   __static_attributes____classcell__)r   s   @r   r   r   %   s     #>[ >] > ]]_ DH#%04"' r1r1 ??T%//%::TAr1 	r1
 !r1 #'+r1 4Zr1 r1 
u	$r1 r1r   r   )loggingrP   modelsr   
schedulersr   utilsr   utils.torch_utilsr   pipeline_utilsr	   r
   	getLoggerrJ   r.   torch_xla.core.xla_modelcore	xla_modelr;   r:   r   rH   r   r   <module>rc      sX      ! ' + - C 
		8	$ ))MML1$ L1r   