code: 
  
  
  
  
  
  import torch
  
  from diffusers import HeunDiscreteScheduler
  from diffusers.utils import torch_device
  
  from .test_schedulers import SchedulerCommonTest
  
  
  
  class 							_A (    _a							):
      """simple docstring"""
  
      lowerCamelCase  :       Any   =   (HeunDiscreteScheduler,)
      lowerCamelCase  :       Optional[int]   =   10
  
  
  
      def _a       (							self			:    Optional[Any]   ,    **__SCREAMING_SNAKE_CASE			:    Tuple			)			->       List[str]:
             __UpperCAmelCase    							={
                 """num_train_timesteps""": 1100,
                 """beta_start""": 0.0_001,
                 """beta_end""": 0.02,
                 """beta_schedule""": """linear""",
             }
  
             config.update(**__SCREAMING_SNAKE_CASE			)
             return config
  
  
  
      def _a       (							self			:    int			)			->       str:
             for timesteps in [10, 50, 100, 1000]:
                    self.check_over_configs(num_train_timesteps=__SCREAMING_SNAKE_CASE			)
  
  
  
      def _a       (							self			:    str			)			->       List[Any]:
             for beta_start, beta_end in zip([0.00_001, 0.0_001, 0.001]   ,    [0.0_002, 0.002, 0.02]			):
                    self.check_over_configs(beta_start=__SCREAMING_SNAKE_CASE   ,    beta_end=__SCREAMING_SNAKE_CASE			)
  
  
  
      def _a       (							self			:    Any			)			->       Union[str, Any]:
             for schedule in ["linear", "scaled_linear", "exp"]:
                    self.check_over_configs(beta_schedule=__SCREAMING_SNAKE_CASE			)
  
  
  
      def _a       (							self			:    Optional[int]			)			->       Any:
             for clip_sample_range in [1.0, 2.0, 3.0]:
                    self.check_over_configs(clip_sample_range=__SCREAMING_SNAKE_CASE   ,    clip_sample=__SCREAMING_SNAKE_CASE			)
  
  
  
      def _a       (							self			:    List[str]			)			->       str:
             for prediction_type in ["epsilon", "v_prediction", "sample"]:
                    self.check_over_configs(prediction_type=__SCREAMING_SNAKE_CASE			)
  
  
  
      def _a       (							self			:    Union[str, Any]			)			->       Union[str, Any]:
             __UpperCAmelCase    							=self.scheduler_classes[0]
             __UpperCAmelCase    							=self.get_scheduler_config()
             __UpperCAmelCase    							=scheduler_class(**__SCREAMING_SNAKE_CASE			)
  
             scheduler.set_timesteps(self.num_inference_steps			)
  
             __UpperCAmelCase    							=self.dummy_model()
             __UpperCAmelCase    							=self.dummy_sample_deter * scheduler.init_noise_sigma
             __UpperCAmelCase    							=sample.to(__SCREAMING_SNAKE_CASE			)
  
             for i, t in enumerate(scheduler.timesteps			):
                    __UpperCAmelCase    							=scheduler.scale_model_input(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE			)
  
                    __UpperCAmelCase    							=model(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE			)
  
                    __UpperCAmelCase    							=scheduler.step(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE			)
                    __UpperCAmelCase    							=output.prev_sample
  
             __UpperCAmelCase    							=torch.sum(torch.abs(__SCREAMING_SNAKE_CASE			)			)
             __UpperCAmelCase    							=torch.mean(torch.abs(__SCREAMING_SNAKE_CASE			)			)
  
             if torch_device in ["cpu", "mps"]:
                    assert abs(result_sum.item() - 0.1_233			) < 1e-2
                    assert abs(result_mean.item() - 0.0_002			) < 1e-3
             else:
                    # CUDA
                    assert abs(result_sum.item() - 0.1_233			) < 1e-2
                    assert abs(result_mean.item() - 0.0_002			) < 1e-3
  
  
  
      def _a       (							self			:    List[str]			)			->       Optional[Any]:
             __UpperCAmelCase    							=self.scheduler_classes[0]
             __UpperCAmelCase    							=self.get_scheduler_config(prediction_type="""v_prediction"""			)
             __UpperCAmelCase    							=scheduler_class(**__SCREAMING_SNAKE_CASE			)
  
             scheduler.set_timesteps(self.num_inference_steps			)
  
             __UpperCAmelCase    							=self.dummy_model()
             __UpperCAmelCase    							=self.dummy_sample_deter * scheduler.init_noise_sigma
             __UpperCAmelCase    							=sample.to(__SCREAMING_SNAKE_CASE			)
  
             for i, t in enumerate(scheduler.timesteps			):
                    __UpperCAmelCase    							=scheduler.scale_model_input(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE			)
  
                    __UpperCAmelCase    							=model(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE			)
  
                    __UpperCAmelCase    							=scheduler.step(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE			)
                    __UpperCAmelCase    							=output.prev_sample
  
             __UpperCAmelCase    							=torch.sum(torch.abs(__SCREAMING_SNAKE_CASE			)			)
             __UpperCAmelCase    							=torch.mean(torch.abs(__SCREAMING_SNAKE_CASE			)			)
  
             if torch_device in ["cpu", "mps"]:
                    assert abs(result_sum.item() - 4.6934e-07			) < 1e-2
                    assert abs(result_mean.item() - 6.1112e-10			) < 1e-3
             else:
                    # CUDA
                    assert abs(result_sum.item() - 4.693_4286_5017_0972e-07			) < 1e-2
                    assert abs(result_mean.item() - 0.0_002			) < 1e-3
  
  
  
      def _a       (							self			:    str			)			->       Union[str, Any]:
             __UpperCAmelCase    							=self.scheduler_classes[0]
             __UpperCAmelCase    							=self.get_scheduler_config()
             __UpperCAmelCase    							=scheduler_class(**__SCREAMING_SNAKE_CASE			)
  
             scheduler.set_timesteps(self.num_inference_steps   ,    device=__SCREAMING_SNAKE_CASE			)
  
             __UpperCAmelCase    							=self.dummy_model()
             __UpperCAmelCase    							=self.dummy_sample_deter.to(__SCREAMING_SNAKE_CASE			) * scheduler.init_noise_sigma
  
             for t in scheduler.timesteps:
                    __UpperCAmelCase    							=scheduler.scale_model_input(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE			)
  
                    __UpperCAmelCase    							=model(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE			)
  
                    __UpperCAmelCase    							=scheduler.step(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE			)
                    __UpperCAmelCase    							=output.prev_sample
  
             __UpperCAmelCase    							=torch.sum(torch.abs(__SCREAMING_SNAKE_CASE			)			)
             __UpperCAmelCase    							=torch.mean(torch.abs(__SCREAMING_SNAKE_CASE			)			)
  
             if str(__SCREAMING_SNAKE_CASE			).startswith("""cpu"""			):
                    # The following sum varies between 148 and 156 on mps. Why?
                    assert abs(result_sum.item() - 0.1_233			) < 1e-2
                    assert abs(result_mean.item() - 0.0_002			) < 1e-3
             elif str(__SCREAMING_SNAKE_CASE			).startswith("""mps"""			):
                    # Larger tolerance on mps
                    assert abs(result_mean.item() - 0.0_002			) < 1e-2
             else:
                    # CUDA
                    assert abs(result_sum.item() - 0.1_233			) < 1e-2
                    assert abs(result_mean.item() - 0.0_002			) < 1e-3
  
  
  
      def _a       (							self			:    Dict			)			->       int:
             __UpperCAmelCase    							=self.scheduler_classes[0]
             __UpperCAmelCase    							=self.get_scheduler_config()
             __UpperCAmelCase    							=scheduler_class(**__SCREAMING_SNAKE_CASE   ,    use_karras_sigmas=__SCREAMING_SNAKE_CASE			)
  
             scheduler.set_timesteps(self.num_inference_steps   ,    device=__SCREAMING_SNAKE_CASE			)
  
             __UpperCAmelCase    							=self.dummy_model()
             __UpperCAmelCase    							=self.dummy_sample_deter.to(__SCREAMING_SNAKE_CASE			) * scheduler.init_noise_sigma
             __UpperCAmelCase    							=sample.to(__SCREAMING_SNAKE_CASE			)
  
             for t in scheduler.timesteps:
                    __UpperCAmelCase    							=scheduler.scale_model_input(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE			)
  
                    __UpperCAmelCase    							=model(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE			)
  
                    __UpperCAmelCase    							=scheduler.step(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE			)
                    __UpperCAmelCase    							=output.prev_sample
  
             __UpperCAmelCase    							=torch.sum(torch.abs(__SCREAMING_SNAKE_CASE			)			)
             __UpperCAmelCase    							=torch.mean(torch.abs(__SCREAMING_SNAKE_CASE			)			)
  
             assert abs(result_sum.item() - 0.00_015			) < 1e-2
             assert abs(result_mean.item() - 1.9869_5545_3503_4695e-07			) < 1e-2
  
  
  
  
  
style_context: 
  
  
  
  
  
  
  from collections import namedtuple
  
  __A  							=  namedtuple("from_to", "from_ to")
  
  __A  							=  {
      "millimeter": "mm",
      "centimeter": "cm",
      "meter": "m",
      "kilometer": "km",
      "inch": "in",
      "inche": "in",  # Trailing 's' has been stripped off
      "feet": "ft",
      "foot": "ft",
      "yard": "yd",
      "mile": "mi",
  }
  
  __A  							=  {
      "mm": from_to(0.001, 10_00),
      "cm": from_to(0.01, 1_00),
      "m": from_to(1, 1),
      "km": from_to(10_00, 0.001),
      "in": from_to(0.0254, 39.3701),
      "ft": from_to(0.3048, 3.2_8084),
      "yd": from_to(0.9144, 1.0_9361),
      "mi": from_to(1609.34, 0.0_0062_1371),
  }
  
  
  
  
  
  
  
  def 			lowercase__  (				A_:	float     ,			A_:	str     ,			A_:	str		)  ->							float:
  
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
         __UpperCAmelCase    							=from_type.lower().rstrip("""s"""		)
         __UpperCAmelCase    							=TYPE_CONVERSION.get(A_     ,			A_		)
         __UpperCAmelCase    							=to_type.lower().rstrip("""s"""		)
         __UpperCAmelCase    							=TYPE_CONVERSION.get(A_     ,			A_		)
         if new_from not in METRIC_CONVERSION:
                __UpperCAmelCase    							=(
                    F'''Invalid \'from_type\' value: {from_type!r}.\n'''
                    F'''Conversion abbreviations are: {", ".join(A_		)}'''
                )
                raise ValueError(A_		)
         if new_to not in METRIC_CONVERSION:
                __UpperCAmelCase    							=(
                    F'''Invalid \'to_type\' value: {to_type!r}.\n'''
                    F'''Conversion abbreviations are: {", ".join(A_		)}'''
                )
                raise ValueError(A_		)
         return value * METRIC_CONVERSION[new_from].from_ * METRIC_CONVERSION[new_to].to
  
  
  if __name__ == "__main__":
     import doctest
  
     doctest.testmod()
  
  
  
  
  