code: 
  
  
  
  
  
  
  """simple docstring"""
  
  
  
  
  
  
  import tempfile
  
  import torch
  
  from diffusers import (
      DEISMultistepScheduler,
      DPMSolverMultistepScheduler,
      DPMSolverSinglestepScheduler,
      UniPCMultistepScheduler,
  )
  
  from .test_schedulers import SchedulerCommonTest
  class 						__lowerCAmelCase   (			UpperCAmelCase       ):
  
  
  
  
  
  
  
    '''simple docstring'''
  
  
    __lowerCamelCase       :    Optional[int]     	=			(DPMSolverMultistepScheduler,)
    __lowerCamelCase       :    Union[str, Any]     	=			(("num_inference_steps", 25),)
    def 					UpperCamelCase__   (      self:		str				,			**UpperCamelCase_:		Any					):
       UpperCamelCase_     ={
           "num_train_timesteps": 1000,
           "beta_start": 0.0001,
           "beta_end": 0.02,
           "beta_schedule": "linear",
           "solver_order": 2,
           "prediction_type": "epsilon",
           "thresholding": False,
           "sample_max_value": 1.0,
           "algorithm_type": "dpmsolver++",
           "solver_type": "midpoint",
           "lower_order_final": False,
           "lambda_min_clipped": -float("inf"					),
           "variance_type": None,
       }
  
       config.update(**UpperCamelCase_					)
       return config
    def 					UpperCamelCase__   (      self:		Dict				,			UpperCamelCase_:		Optional[int]=0				,			**UpperCamelCase_:		int					):
       UpperCamelCase_     =dict(self.forward_default_kwargs					)
       UpperCamelCase_     =kwargs.pop("num_inference_steps"				,			UpperCamelCase_					)
       UpperCamelCase_     =self.dummy_sample
       UpperCamelCase_     =0.1 * sample
       UpperCamelCase_     =[residual + 0.2, residual + 0.15, residual + 0.10]
  
       for scheduler_class in self.scheduler_classes:
          UpperCamelCase_     =self.get_scheduler_config(**UpperCamelCase_					)
          UpperCamelCase_     =scheduler_class(**UpperCamelCase_					)
          scheduler.set_timesteps(UpperCamelCase_					)
          # copy over dummy past residuals
          UpperCamelCase_     =dummy_past_residuals[: scheduler.config.solver_order]
  
          with tempfile.TemporaryDirectory() as tmpdirname:
             scheduler.save_config(UpperCamelCase_					)
             UpperCamelCase_     =scheduler_class.from_pretrained(UpperCamelCase_					)
             new_scheduler.set_timesteps(UpperCamelCase_					)
             # copy over dummy past residuals
             UpperCamelCase_     =dummy_past_residuals[: new_scheduler.config.solver_order]
  
          UpperCamelCase_    ,							UpperCamelCase_     =sample, sample
          for t in range(UpperCamelCase_				,			time_step + scheduler.config.solver_order + 1					):
             UpperCamelCase_     =scheduler.step(UpperCamelCase_				,			UpperCamelCase_				,			UpperCamelCase_				,			**UpperCamelCase_					).prev_sample
             UpperCamelCase_     =new_scheduler.step(UpperCamelCase_				,			UpperCamelCase_				,			UpperCamelCase_				,			**UpperCamelCase_					).prev_sample
  
             assert torch.sum(torch.abs(output - new_output					)					) < 1e-5, "Scheduler outputs are not identical"
    def 					UpperCamelCase__   (      self:		Tuple					):
       pass
    def 					UpperCamelCase__   (      self:		Union[str, Any]				,			UpperCamelCase_:		Optional[Any]=0				,			**UpperCamelCase_:		Optional[Any]					):
       UpperCamelCase_     =dict(self.forward_default_kwargs					)
       UpperCamelCase_     =kwargs.pop("num_inference_steps"				,			UpperCamelCase_					)
       UpperCamelCase_     =self.dummy_sample
       UpperCamelCase_     =0.1 * sample
       UpperCamelCase_     =[residual + 0.2, residual + 0.15, residual + 0.10]
  
       for scheduler_class in self.scheduler_classes:
          UpperCamelCase_     =self.get_scheduler_config()
          UpperCamelCase_     =scheduler_class(**UpperCamelCase_					)
          scheduler.set_timesteps(UpperCamelCase_					)
  
          # copy over dummy past residuals (must be after setting timesteps)
          UpperCamelCase_     =dummy_past_residuals[: scheduler.config.solver_order]
  
          with tempfile.TemporaryDirectory() as tmpdirname:
             scheduler.save_config(UpperCamelCase_					)
             UpperCamelCase_     =scheduler_class.from_pretrained(UpperCamelCase_					)
             # copy over dummy past residuals
             new_scheduler.set_timesteps(UpperCamelCase_					)
  
             # copy over dummy past residual (must be after setting timesteps)
             UpperCamelCase_     =dummy_past_residuals[: new_scheduler.config.solver_order]
  
          UpperCamelCase_     =scheduler.step(UpperCamelCase_				,			UpperCamelCase_				,			UpperCamelCase_				,			**UpperCamelCase_					).prev_sample
          UpperCamelCase_     =new_scheduler.step(UpperCamelCase_				,			UpperCamelCase_				,			UpperCamelCase_				,			**UpperCamelCase_					).prev_sample
  
          assert torch.sum(torch.abs(output - new_output					)					) < 1e-5, "Scheduler outputs are not identical"
    def 					UpperCamelCase__   (      self:		Optional[int]				,			UpperCamelCase_:		Optional[Any]=None				,			**UpperCamelCase_:		str					):
       if scheduler is None:
          UpperCamelCase_     =self.scheduler_classes[0]
          UpperCamelCase_     =self.get_scheduler_config(**UpperCamelCase_					)
          UpperCamelCase_     =scheduler_class(**UpperCamelCase_					)
  
       UpperCamelCase_     =10
       UpperCamelCase_     =self.dummy_model()
       UpperCamelCase_     =self.dummy_sample_deter
       scheduler.set_timesteps(UpperCamelCase_					)
  
       for i, t in enumerate(scheduler.timesteps					):
          UpperCamelCase_     =model(UpperCamelCase_				,			UpperCamelCase_					)
          UpperCamelCase_     =scheduler.step(UpperCamelCase_				,			UpperCamelCase_				,			UpperCamelCase_					).prev_sample
  
       return sample
    def 					UpperCamelCase__   (      self:		Any					):
       UpperCamelCase_     =dict(self.forward_default_kwargs					)
  
       UpperCamelCase_     =kwargs.pop("num_inference_steps"				,			UpperCamelCase_					)
  
       for scheduler_class in self.scheduler_classes:
          UpperCamelCase_     =self.get_scheduler_config()
          UpperCamelCase_     =scheduler_class(**UpperCamelCase_					)
  
          UpperCamelCase_     =self.dummy_sample
          UpperCamelCase_     =0.1 * sample
  
          if num_inference_steps is not None and hasattr(UpperCamelCase_				,			"set_timesteps"					):
             scheduler.set_timesteps(UpperCamelCase_					)
          elif num_inference_steps is not None and not hasattr(UpperCamelCase_				,			"set_timesteps"					):
             UpperCamelCase_     =num_inference_steps
  
          # copy over dummy past residuals (must be done after set_timesteps)
          UpperCamelCase_     =[residual + 0.2, residual + 0.15, residual + 0.10]
          UpperCamelCase_     =dummy_past_residuals[: scheduler.config.solver_order]
  
          UpperCamelCase_     =scheduler.timesteps[5]
          UpperCamelCase_     =scheduler.timesteps[6]
  
          UpperCamelCase_     =scheduler.step(UpperCamelCase_				,			UpperCamelCase_				,			UpperCamelCase_				,			**UpperCamelCase_					).prev_sample
          UpperCamelCase_     =scheduler.step(UpperCamelCase_				,			UpperCamelCase_				,			UpperCamelCase_				,			**UpperCamelCase_					).prev_sample
  
          self.assertEqual(output_a.shape				,			sample.shape					)
          self.assertEqual(output_a.shape				,			output_a.shape					)
    def 					UpperCamelCase__   (      self:		str					):
       for timesteps in [25, 50, 100, 999, 1000]:
          self.check_over_configs(num_train_timesteps=UpperCamelCase_					)
    def 					UpperCamelCase__   (      self:		Any					):
       self.check_over_configs(thresholding=UpperCamelCase_					)
       for order in [1, 2, 3]:
          for solver_type in ["midpoint", "heun"]:
             for threshold in [0.5, 1.0, 2.0]:
                for prediction_type in ["epsilon", "sample"]:
                   self.check_over_configs(
                       thresholding=UpperCamelCase_				,			prediction_type=UpperCamelCase_				,			sample_max_value=UpperCamelCase_				,			algorithm_type="dpmsolver++"				,			solver_order=UpperCamelCase_				,			solver_type=UpperCamelCase_				,			)
    def 					UpperCamelCase__   (      self:		str					):
       for prediction_type in ["epsilon", "v_prediction"]:
          self.check_over_configs(prediction_type=UpperCamelCase_					)
    def 					UpperCamelCase__   (      self:		str					):
       for algorithm_type in ["dpmsolver", "dpmsolver++", "sde-dpmsolver", "sde-dpmsolver++"]:
          for solver_type in ["midpoint", "heun"]:
             for order in [1, 2, 3]:
                for prediction_type in ["epsilon", "sample"]:
                   if algorithm_type in ["sde-dpmsolver", "sde-dpmsolver++"]:
                      if order == 3:
                         continue
                   else:
                      self.check_over_configs(
                          solver_order=UpperCamelCase_				,			solver_type=UpperCamelCase_				,			prediction_type=UpperCamelCase_				,			algorithm_type=UpperCamelCase_				,			)
                   UpperCamelCase_     =self.full_loop(
                       solver_order=UpperCamelCase_				,			solver_type=UpperCamelCase_				,			prediction_type=UpperCamelCase_				,			algorithm_type=UpperCamelCase_				,			)
                   assert not torch.isnan(UpperCamelCase_					).any(), "Samples have nan numbers"
    def 					UpperCamelCase__   (      self:		List[Any]					):
       self.check_over_configs(lower_order_final=UpperCamelCase_					)
       self.check_over_configs(lower_order_final=UpperCamelCase_					)
    def 					UpperCamelCase__   (      self:		str					):
       self.check_over_configs(lambda_min_clipped=-float("inf"					)					)
       self.check_over_configs(lambda_min_clipped=-5.1					)
    def 					UpperCamelCase__   (      self:		str					):
       self.check_over_configs(variance_type=UpperCamelCase_					)
       self.check_over_configs(variance_type="learned_range"					)
    def 					UpperCamelCase__   (      self:		Optional[int]					):
       for num_inference_steps in [1, 2, 3, 5, 10, 50, 100, 999, 1000]:
          self.check_over_forward(num_inference_steps=UpperCamelCase_				,			time_step=0					)
    def 					UpperCamelCase__   (      self:		Optional[Any]					):
       UpperCamelCase_     =self.full_loop()
       UpperCamelCase_     =torch.mean(torch.abs(UpperCamelCase_					)					)
  
       assert abs(result_mean.item() - 0.3301					) < 1e-3
    def 					UpperCamelCase__   (      self:		Optional[int]					):
       UpperCamelCase_     =self.full_loop(thresholding=UpperCamelCase_				,			dynamic_thresholding_ratio=0.87				,			sample_max_value=0.5					)
       UpperCamelCase_     =torch.mean(torch.abs(UpperCamelCase_					)					)
  
       assert abs(result_mean.item() - 1.1364					) < 1e-3
    def 					UpperCamelCase__   (      self:		int					):
       UpperCamelCase_     =self.full_loop(prediction_type="v_prediction"					)
       UpperCamelCase_     =torch.mean(torch.abs(UpperCamelCase_					)					)
  
       assert abs(result_mean.item() - 0.2251					) < 1e-3
    def 					UpperCamelCase__   (      self:		Optional[Any]					):
       UpperCamelCase_     =self.full_loop(prediction_type="v_prediction"				,			use_karras_sigmas=UpperCamelCase_					)
       UpperCamelCase_     =torch.mean(torch.abs(UpperCamelCase_					)					)
  
       assert abs(result_mean.item() - 0.2096					) < 1e-3
    def 					UpperCamelCase__   (      self:		List[Any]					):
       # make sure that iterating over schedulers with same config names gives same results
       # for defaults
       UpperCamelCase_     =DPMSolverMultistepScheduler(**self.get_scheduler_config()					)
       UpperCamelCase_     =self.full_loop(scheduler=UpperCamelCase_					)
       UpperCamelCase_     =torch.mean(torch.abs(UpperCamelCase_					)					)
  
       assert abs(result_mean.item() - 0.3301					) < 1e-3
  
       UpperCamelCase_     =DPMSolverSinglestepScheduler.from_config(scheduler.config					)
       UpperCamelCase_     =UniPCMultistepScheduler.from_config(scheduler.config					)
       UpperCamelCase_     =DEISMultistepScheduler.from_config(scheduler.config					)
       UpperCamelCase_     =DPMSolverMultistepScheduler.from_config(scheduler.config					)
  
       UpperCamelCase_     =self.full_loop(scheduler=UpperCamelCase_					)
       UpperCamelCase_     =torch.mean(torch.abs(UpperCamelCase_					)					)
  
       assert abs(result_mean.item() - 0.3301					) < 1e-3
    def 					UpperCamelCase__   (      self:		List[str]					):
       UpperCamelCase_     =self.scheduler_classes[0]
       UpperCamelCase_     =self.get_scheduler_config(thresholding=UpperCamelCase_				,			dynamic_thresholding_ratio=0					)
       UpperCamelCase_     =scheduler_class(**UpperCamelCase_					)
  
       UpperCamelCase_     =10
       UpperCamelCase_     =self.dummy_model()
       UpperCamelCase_     =self.dummy_sample_deter.half()
       scheduler.set_timesteps(UpperCamelCase_					)
  
       for i, t in enumerate(scheduler.timesteps					):
          UpperCamelCase_     =model(UpperCamelCase_				,			UpperCamelCase_					)
          UpperCamelCase_     =scheduler.step(UpperCamelCase_				,			UpperCamelCase_				,			UpperCamelCase_					).prev_sample
  
       assert sample.dtype == torch.floataa
  
  
  
  
  
    def 					UpperCamelCase__   (      self:		Dict				,			**UpperCamelCase_:		Dict					):
       for scheduler_class in self.scheduler_classes:
          UpperCamelCase_     =self.get_scheduler_config(**UpperCamelCase_					)
          UpperCamelCase_     =scheduler_class(**UpperCamelCase_					)
  
          scheduler.set_timesteps(scheduler.config.num_train_timesteps					)
          assert len(scheduler.timesteps.unique()					) == scheduler.num_inference_steps
  
style_context: 
  
  
  
  
  
  
  """simple docstring"""
  
  
  
  
  
  
  import unittest
  from dataclasses import dataclass
  from typing import List, Union
  
  import numpy as np
  import PIL.Image
  
  from diffusers.utils.outputs import BaseOutput
  @dataclass
  class 						__lowerCAmelCase   (			UpperCAmelCase       ):
  
  
  
  
  
  
  
    '''simple docstring'''
  
  
    __lowerCamelCase       :    Union[List[PIL.Image.Image], np.ndarray]
  
  
  
  
  class 						__lowerCAmelCase   (			unittest.TestCase       ):
  
  
  
  
  
  
  
    '''simple docstring'''
  
  
    def 					UpperCamelCase__   (      self:		Tuple					):
       UpperCamelCase_     =CustomOutput(images=np.random.rand(1				,			3				,			4				,			4					)					)
  
       # check every way of getting the attribute
       assert isinstance(outputs.images				,			np.ndarray					)
       assert outputs.images.shape == (1, 3, 4, 4)
       assert isinstance(outputs["images"]				,			np.ndarray					)
       assert outputs["images"].shape == (1, 3, 4, 4)
       assert isinstance(outputs[0]				,			np.ndarray					)
       assert outputs[0].shape == (1, 3, 4, 4)
  
       # test with a non-tensor attribute
       UpperCamelCase_     =CustomOutput(images=[PIL.Image.new("RGB"				,			(4, 4)					)]					)
  
       # check every way of getting the attribute
       assert isinstance(outputs.images				,			UpperCamelCase_					)
       assert isinstance(outputs.images[0]				,			PIL.Image.Image					)
       assert isinstance(outputs["images"]				,			UpperCamelCase_					)
       assert isinstance(outputs["images"][0]				,			PIL.Image.Image					)
       assert isinstance(outputs[0]				,			UpperCamelCase_					)
       assert isinstance(outputs[0][0]				,			PIL.Image.Image					)
  
  
  
  
  
    def 					UpperCamelCase__   (      self:		Optional[int]					):
       # test output reinitialization with a `dict` for compatibility with `accelerate`
       UpperCamelCase_     =CustomOutput({"images": np.random.rand(1				,			3				,			4				,			4					)}					)
  
       # check every way of getting the attribute
       assert isinstance(outputs.images				,			np.ndarray					)
       assert outputs.images.shape == (1, 3, 4, 4)
       assert isinstance(outputs["images"]				,			np.ndarray					)
       assert outputs["images"].shape == (1, 3, 4, 4)
       assert isinstance(outputs[0]				,			np.ndarray					)
       assert outputs[0].shape == (1, 3, 4, 4)
  
       # test with a non-tensor attribute
       UpperCamelCase_     =CustomOutput({"images": [PIL.Image.new("RGB"				,			(4, 4)					)]}					)
  
       # check every way of getting the attribute
       assert isinstance(outputs.images				,			UpperCamelCase_					)
       assert isinstance(outputs.images[0]				,			PIL.Image.Image					)
       assert isinstance(outputs["images"]				,			UpperCamelCase_					)
       assert isinstance(outputs["images"][0]				,			PIL.Image.Image					)
       assert isinstance(outputs[0]				,			UpperCamelCase_					)
       assert isinstance(outputs[0][0]				,			PIL.Image.Image					)
  