





'''simple docstring'''






import unittest

import numpy as np
import torch

from diffusers import PNDMPipeline, PNDMScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()
class 					__snake_case  (					unittest.TestCase							):






   '''simple docstring'''





   @property
   def 		__UpperCamelCase						(							self       ):
    torch.manual_seed(0       )
    snake_case__     :					Dict    =  UNetaDModel(
        block_out_channels=(3_2, 6_4)	,		layers_per_block=2	,		sample_size=3_2	,		in_channels=3	,		out_channels=3	,		down_block_types=("""DownBlock2D""", """AttnDownBlock2D""")	,		up_block_types=("""AttnUpBlock2D""", """UpBlock2D""")	,		)
    return model


   def 		__UpperCamelCase						(							self       ):
    snake_case__     :					Tuple    =  self.dummy_uncond_unet
    snake_case__     :					int    =  PNDMScheduler()

    snake_case__     :					int    =  PNDMPipeline(unet=__SCREAMING_SNAKE_CASE	,		scheduler=__SCREAMING_SNAKE_CASE       )
    pndm.to(__SCREAMING_SNAKE_CASE       )
    pndm.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE       )

    snake_case__     :					Optional[int]    =  torch.manual_seed(0       )
    snake_case__     :					Union[str, Any]    =  pndm(generator=__SCREAMING_SNAKE_CASE	,		num_inference_steps=2_0	,		output_type="""numpy"""       ).images

    snake_case__     :					Tuple    =  torch.manual_seed(0       )
    snake_case__     :					Union[str, Any]    =  pndm(generator=__SCREAMING_SNAKE_CASE	,		num_inference_steps=2_0	,		output_type="""numpy"""	,		return_dict=__SCREAMING_SNAKE_CASE       )[0]

    snake_case__     :					Dict    =  image[0, -3:, -3:, -1]
    snake_case__     :					List[str]    =  image_from_tuple[0, -3:, -3:, -1]

    assert image.shape == (1, 3_2, 3_2, 3)
    snake_case__     :					Dict    =  np.array([1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0]       )

    assert np.abs(image_slice.flatten() - expected_slice       ).max() < 1e-2
    assert np.abs(image_from_tuple_slice.flatten() - expected_slice       ).max() < 1e-2



@slow
@require_torch
class 					__snake_case  (					unittest.TestCase							):






   '''simple docstring'''





   def 		__UpperCamelCase						(							self       ):
    snake_case__     :					Tuple    =  """google/ddpm-cifar10-32"""

    snake_case__     :					Dict    =  UNetaDModel.from_pretrained(__SCREAMING_SNAKE_CASE       )
    snake_case__     :					str    =  PNDMScheduler()

    snake_case__     :					Optional[int]    =  PNDMPipeline(unet=__SCREAMING_SNAKE_CASE	,		scheduler=__SCREAMING_SNAKE_CASE       )
    pndm.to(__SCREAMING_SNAKE_CASE       )
    pndm.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE       )
    snake_case__     :					Optional[Any]    =  torch.manual_seed(0       )
    snake_case__     :					str    =  pndm(generator=__SCREAMING_SNAKE_CASE	,		output_type="""numpy"""       ).images

    snake_case__     :					str    =  image[0, -3:, -3:, -1]

    assert image.shape == (1, 3_2, 3_2, 3)
    snake_case__     :					Optional[Any]    =  np.array([0.1564, 0.1_4645, 0.1406, 0.1_4715, 0.1_2425, 0.1_4045, 0.1_3115, 0.1_2175, 0.125]       )

    assert np.abs(image_slice.flatten() - expected_slice       ).max() < 1e-2







'''simple docstring'''



from ..utils import DummyObject, requires_backends



class 				_snake_case					(   metaclass=a_			):
  SCREAMING_SNAKE_CASE			:       int				=     ['''torch''', '''transformers''', '''onnx''']

  def __init__(				self      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(self      , ['torch', 'transformers', 'onnx']	)

  @classmethod
  def   _SCREAMING_SNAKE_CASE				(				cls      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(cls      , ['torch', 'transformers', 'onnx']	)


  @classmethod
  def   _SCREAMING_SNAKE_CASE				(				cls      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(cls      , ['torch', 'transformers', 'onnx']	)



class 				_snake_case					(   metaclass=a_			):
  SCREAMING_SNAKE_CASE			:       List[Any]				=     ['''torch''', '''transformers''', '''onnx''']

  def __init__(				self      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(self      , ['torch', 'transformers', 'onnx']	)

  @classmethod
  def   _SCREAMING_SNAKE_CASE				(				cls      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(cls      , ['torch', 'transformers', 'onnx']	)


  @classmethod
  def   _SCREAMING_SNAKE_CASE				(				cls      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(cls      , ['torch', 'transformers', 'onnx']	)



class 				_snake_case					(   metaclass=a_			):
  SCREAMING_SNAKE_CASE			:       int				=     ['''torch''', '''transformers''', '''onnx''']

  def __init__(				self      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(self      , ['torch', 'transformers', 'onnx']	)

  @classmethod
  def   _SCREAMING_SNAKE_CASE				(				cls      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(cls      , ['torch', 'transformers', 'onnx']	)


  @classmethod
  def   _SCREAMING_SNAKE_CASE				(				cls      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(cls      , ['torch', 'transformers', 'onnx']	)



class 				_snake_case					(   metaclass=a_			):
  SCREAMING_SNAKE_CASE			:       Dict				=     ['''torch''', '''transformers''', '''onnx''']

  def __init__(				self      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(self      , ['torch', 'transformers', 'onnx']	)

  @classmethod
  def   _SCREAMING_SNAKE_CASE				(				cls      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(cls      , ['torch', 'transformers', 'onnx']	)


  @classmethod
  def   _SCREAMING_SNAKE_CASE				(				cls      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(cls      , ['torch', 'transformers', 'onnx']	)



class 				_snake_case					(   metaclass=a_			):
  SCREAMING_SNAKE_CASE			:       List[Any]				=     ['''torch''', '''transformers''', '''onnx''']

  def __init__(				self      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(self      , ['torch', 'transformers', 'onnx']	)

  @classmethod
  def   _SCREAMING_SNAKE_CASE				(				cls      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(cls      , ['torch', 'transformers', 'onnx']	)


  @classmethod
  def   _SCREAMING_SNAKE_CASE				(				cls      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(cls      , ['torch', 'transformers', 'onnx']	)



class 				_snake_case					(   metaclass=a_			):
  SCREAMING_SNAKE_CASE			:       Optional[Any]				=     ['''torch''', '''transformers''', '''onnx''']

  def __init__(				self      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(self      , ['torch', 'transformers', 'onnx']	)

  @classmethod
  def   _SCREAMING_SNAKE_CASE				(				cls      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(cls      , ['torch', 'transformers', 'onnx']	)


  @classmethod
  def   _SCREAMING_SNAKE_CASE				(				cls      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      requires_backends(cls      , ['torch', 'transformers', 'onnx']	)





