code: 
  
  
  
  
  
  import torch
  
  from diffusers import HeunDiscreteScheduler
  from diffusers.utils import torch_device
  
  from .test_schedulers import SchedulerCommonTest
  
  class 				A    (__UpperCAmelCase				):
        _SCREAMING_SNAKE_CASE					=							(HeunDiscreteScheduler,)
        _SCREAMING_SNAKE_CASE					=							10
  
  
  
        def    __a (					self     ,  **lowercase_					)      ->   Dict:
  
  
  
               '''simple docstring'''
  
               _snake_case      :							Any     				=						{
                   '''num_train_timesteps''': 1100,
                   '''beta_start''': 0.0001,
                   '''beta_end''': 0.02,
                   '''beta_schedule''': '''linear''',
               }
  
               config.update(**lowercase_					)
               return config
  
  
  
        def    __a (					self					)      ->   Optional[int]:
  
  
  
               '''simple docstring'''
  
               for timesteps in [10, 50, 100, 1000]:
                      self.check_over_configs(num_train_timesteps=lowercase_					)
  
  
  
        def    __a (					self					)      ->   Any:
  
  
  
               '''simple docstring'''
  
               for beta_start, beta_end in zip([0.0_0001, 0.0001, 0.001]     ,  [0.0002, 0.002, 0.02]					):
                      self.check_over_configs(beta_start=lowercase_     ,  beta_end=lowercase_					)
  
  
  
        def    __a (					self					)      ->   Optional[Any]:
  
  
  
               '''simple docstring'''
  
               for schedule in ["linear", "scaled_linear", "exp"]:
                      self.check_over_configs(beta_schedule=lowercase_					)
  
  
  
        def    __a (					self					)      ->   List[str]:
  
  
  
               '''simple docstring'''
  
               for clip_sample_range in [1.0, 2.0, 3.0]:
                      self.check_over_configs(clip_sample_range=lowercase_     ,  clip_sample=lowercase_					)
  
  
  
        def    __a (					self					)      ->   Optional[int]:
  
  
  
               '''simple docstring'''
  
               for prediction_type in ["epsilon", "v_prediction", "sample"]:
                      self.check_over_configs(prediction_type=lowercase_					)
  
  
  
        def    __a (					self					)      ->   Tuple:
  
  
  
               '''simple docstring'''
  
               _snake_case      :							str     				=						self.scheduler_classes[0]
               _snake_case      :							List[Any]     				=						self.get_scheduler_config()
               _snake_case      :							Optional[Any]     				=						scheduler_class(**lowercase_					)
  
               scheduler.set_timesteps(self.num_inference_steps					)
  
               _snake_case      :							Any     				=						self.dummy_model()
               _snake_case      :							List[str]     				=						self.dummy_sample_deter * scheduler.init_noise_sigma
               _snake_case      :							str     				=						sample.to(lowercase_					)
  
               for i, t in enumerate(scheduler.timesteps					):
                      _snake_case      :							Any     				=						scheduler.scale_model_input(lowercase_     ,  lowercase_					)
  
                      _snake_case      :							Dict     				=						model(lowercase_     ,  lowercase_					)
  
                      _snake_case      :							Optional[Any]     				=						scheduler.step(lowercase_     ,  lowercase_     ,  lowercase_					)
                      _snake_case      :							Any     				=						output.prev_sample
  
               _snake_case      :							List[str]     				=						torch.sum(torch.abs(lowercase_					)					)
               _snake_case      :							List[Any]     				=						torch.mean(torch.abs(lowercase_					)					)
  
               if torch_device in ["cpu", "mps"]:
                      assert abs(result_sum.item() - 0.1233					) < 1E-2
                      assert abs(result_mean.item() - 0.0002					) < 1E-3
               else:
                      # CUDA
                      assert abs(result_sum.item() - 0.1233					) < 1E-2
                      assert abs(result_mean.item() - 0.0002					) < 1E-3
  
  
  
        def    __a (					self					)      ->   int:
  
  
  
               '''simple docstring'''
  
               _snake_case      :							Any     				=						self.scheduler_classes[0]
               _snake_case      :							Any     				=						self.get_scheduler_config(prediction_type='''v_prediction'''					)
               _snake_case      :							Optional[Any]     				=						scheduler_class(**lowercase_					)
  
               scheduler.set_timesteps(self.num_inference_steps					)
  
               _snake_case      :							List[Any]     				=						self.dummy_model()
               _snake_case      :							int     				=						self.dummy_sample_deter * scheduler.init_noise_sigma
               _snake_case      :							Dict     				=						sample.to(lowercase_					)
  
               for i, t in enumerate(scheduler.timesteps					):
                      _snake_case      :							Tuple     				=						scheduler.scale_model_input(lowercase_     ,  lowercase_					)
  
                      _snake_case      :							Optional[int]     				=						model(lowercase_     ,  lowercase_					)
  
                      _snake_case      :							Any     				=						scheduler.step(lowercase_     ,  lowercase_     ,  lowercase_					)
                      _snake_case      :							Union[str, Any]     				=						output.prev_sample
  
               _snake_case      :							str     				=						torch.sum(torch.abs(lowercase_					)					)
               _snake_case      :							Any     				=						torch.mean(torch.abs(lowercase_					)					)
  
               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.0002					) < 1E-3
  
  
  
        def    __a (					self					)      ->   List[str]:
  
  
  
               '''simple docstring'''
  
               _snake_case      :							Dict     				=						self.scheduler_classes[0]
               _snake_case      :							Optional[int]     				=						self.get_scheduler_config()
               _snake_case      :							int     				=						scheduler_class(**lowercase_					)
  
               scheduler.set_timesteps(self.num_inference_steps     ,  device=lowercase_					)
  
               _snake_case      :							Tuple     				=						self.dummy_model()
               _snake_case      :							List[str]     				=						self.dummy_sample_deter.to(lowercase_					) * scheduler.init_noise_sigma
  
               for t in scheduler.timesteps:
                      _snake_case      :							List[str]     				=						scheduler.scale_model_input(lowercase_     ,  lowercase_					)
  
                      _snake_case      :							Union[str, Any]     				=						model(lowercase_     ,  lowercase_					)
  
                      _snake_case      :							Optional[int]     				=						scheduler.step(lowercase_     ,  lowercase_     ,  lowercase_					)
                      _snake_case      :							Tuple     				=						output.prev_sample
  
               _snake_case      :							List[str]     				=						torch.sum(torch.abs(lowercase_					)					)
               _snake_case      :							Any     				=						torch.mean(torch.abs(lowercase_					)					)
  
               if str(lowercase_					).startswith('''cpu'''					):
                      # The following sum varies between 148 and 156 on mps. Why?
                      assert abs(result_sum.item() - 0.1233					) < 1E-2
                      assert abs(result_mean.item() - 0.0002					) < 1E-3
               elif str(lowercase_					).startswith('''mps'''					):
                      # Larger tolerance on mps
                      assert abs(result_mean.item() - 0.0002					) < 1E-2
               else:
                      # CUDA
                      assert abs(result_sum.item() - 0.1233					) < 1E-2
                      assert abs(result_mean.item() - 0.0002					) < 1E-3
  
  
  
        def    __a (					self					)      ->   Optional[Any]:
  
  
  
               '''simple docstring'''
  
               _snake_case      :							Tuple     				=						self.scheduler_classes[0]
               _snake_case      :							Optional[Any]     				=						self.get_scheduler_config()
               _snake_case      :							List[Any]     				=						scheduler_class(**lowercase_     ,  use_karras_sigmas=lowercase_					)
  
               scheduler.set_timesteps(self.num_inference_steps     ,  device=lowercase_					)
  
               _snake_case      :							Tuple     				=						self.dummy_model()
               _snake_case      :							Any     				=						self.dummy_sample_deter.to(lowercase_					) * scheduler.init_noise_sigma
               _snake_case      :							Any     				=						sample.to(lowercase_					)
  
               for t in scheduler.timesteps:
                      _snake_case      :							int     				=						scheduler.scale_model_input(lowercase_     ,  lowercase_					)
  
                      _snake_case      :							int     				=						model(lowercase_     ,  lowercase_					)
  
                      _snake_case      :							Optional[int]     				=						scheduler.step(lowercase_     ,  lowercase_     ,  lowercase_					)
                      _snake_case      :							Optional[Any]     				=						output.prev_sample
  
               _snake_case      :							List[str]     				=						torch.sum(torch.abs(lowercase_					)					)
               _snake_case      :							List[str]     				=						torch.mean(torch.abs(lowercase_					)					)
  
               assert abs(result_sum.item() - 0.0_0015					) < 1E-2
               assert abs(result_mean.item() - 1.9869_5545_3503_4695E-07					) < 1E-2
  
  
  
  
  
  
  
style_context: 
  
  
  
  
  
  from functools import partial
  from typing import Any, Callable, Dict, List, Type, TypeVar, Union, overload
  
  import torch
  import torch.nn as nn
  import torch.types
  
  
  
  
  def 						A_			(  lowercase_      ,		lowercase_      ,		lowercase_  )			->						torch.Tensor:
         # The first operation in a checkpoint can't be in-place, but it's
         # nice to have in-place addition during inference. Thus...
         if not inplace:
                _snake_case      :							Any     				=						ma + ma
         else:
                ma += ma
  
         return ma
  
  
  
  
  def 						A_			(  lowercase_      ,		lowercase_  )			->						torch.Tensor:
         _snake_case      :							str     				=						-1 * len(lowercase_  )
         _snake_case      :							Any     				=						list(range(len(tensor.shape[:zero_index]  )  )  )
         return tensor.permute(first_inds + [zero_index + i for i in inds]  )
  
  
  
  
  def 						A_			(  lowercase_      ,		lowercase_  )			->						torch.Tensor:
         return t.reshape(t.shape[:-no_dims] + (-1,)  )
  
  
  
  
  def 						A_			(  lowercase_      ,		lowercase_      ,		lowercase_      ,		lowercase_ = 1E-4  )			->						torch.Tensor:
         _snake_case      :							Any     				=						mask.expand(*value.shape  )
         return torch.sum(mask * value      ,		dim=lowercase_  ) / (eps + torch.sum(lowercase_      ,		dim=lowercase_  ))
  
  
  
  
  def 						A_			(  lowercase_      ,		lowercase_ = 2.31_25      ,		lowercase_ = 21.68_75      ,		lowercase_ = 64  )			->						torch.Tensor:
         _snake_case      :							int     				=						torch.linspace(lowercase_      ,		lowercase_      ,		no_bins - 1      ,		device=pts.device  )
         _snake_case      :							Optional[Any]     				=						torch.sqrt(torch.sum((pts.unsqueeze(-2  ) - pts.unsqueeze(-3  )) ** 2      ,		dim=-1  )  )
         return torch.bucketize(lowercase_      ,		lowercase_  )
  
  
  
  
  def 						A_			(  lowercase_      ,		lowercase_  )			->						dict:
         _snake_case      :							Dict     				=						dicts[0]
         _snake_case      :							str     				=						{}
         for k, v in first.items():
                _snake_case      :							List[Any]     				=						[d[k] for d in dicts]
                if isinstance(lowercase_      ,		lowercase_  ):
                       _snake_case      :							Any     				=						dict_multimap(lowercase_      ,		lowercase_  )
                else:
                       _snake_case      :							Dict     				=						fn(lowercase_  )
  
         return new_dict
  
  
  
  
  def 						A_			(  lowercase_      ,		lowercase_  )			->						torch.Tensor:
         _snake_case      :							str     				=						v_bins.view(((1,) * len(x.shape  )) + (len(lowercase_  ),)  )
         _snake_case      :							Union[str, Any]     				=						x[..., None] - reshaped_bins
         _snake_case      :							Optional[Any]     				=						torch.argmin(torch.abs(lowercase_  )      ,		dim=-1  )
         return nn.functional.one_hot(lowercase_      ,		num_classes=len(lowercase_  )  ).float()
  
  
  
  
  def 						A_			(  lowercase_      ,		lowercase_      ,		lowercase_ = 0      ,		lowercase_ = 0  )			->						torch.Tensor:
         _snake_case      :							List[Union[slice, torch.Tensor]]     				=						[]
         for i, s in enumerate(data.shape[:no_batch_dims]  ):
                _snake_case      :							Optional[Any]     				=						torch.arange(lowercase_  )
                _snake_case      :							Union[str, Any]     				=						r.view(*(*((1,) * i), -1, *((1,) * (len(inds.shape  ) - i - 1)))  )
                ranges.append(lowercase_  )
  
         _snake_case      :							List[Union[slice, torch.Tensor]]     				=						[slice(lowercase_  ) for _ in range(len(data.shape  ) - no_batch_dims  )]
         _snake_case      :							Union[str, Any]     				=						inds
         ranges.extend(lowercase_  )
         # Matt note: Editing this to get around the behaviour of using a list as an array index changing
         # in recent Numpy versions
         return data[tuple(lowercase_  )]
  
  
  lowerCAmelCase_   =   TypeVar("T")
  
  
  
  
  def 						A_			(  lowercase_      ,		lowercase_      ,		lowercase_  )			->						Dict[Any, Union[dict, list, tuple, Any]]:
         _snake_case      :							Dict[Any, Union[dict, list, tuple, Any]]     				=						{}
         for k, v in dic.items():
                if isinstance(lowercase_      ,		lowercase_  ):
                       _snake_case      :							Dict     				=						dict_map(lowercase_      ,		lowercase_      ,		lowercase_  )
                else:
                       _snake_case      :							List[Any]     				=						tree_map(lowercase_      ,		lowercase_      ,		lowercase_  )
  
         return new_dict
  
  
  
  
  @overload
  def 						A_			(  lowercase_      ,		lowercase_      ,		lowercase_  )			->						Any:
         ...
  
  
  
  
  @overload
  def 						A_			(  lowercase_      ,		lowercase_      ,		lowercase_  )			->						dict:
         ...
  
  
  
  
  @overload
  def 						A_			(  lowercase_      ,		lowercase_      ,		lowercase_  )			->						list:
         ...
  
  
  
  
  @overload
  def 						A_			(  lowercase_      ,		lowercase_      ,		lowercase_  )			->						tuple:
         ...
  
  
  
  
  def 						A_			(  lowercase_      ,		lowercase_      ,		lowercase_  )			->						Any:
         if isinstance(lowercase_      ,		lowercase_  ):
                return dict_map(lowercase_      ,		lowercase_      ,		lowercase_  )
         elif isinstance(lowercase_      ,		lowercase_  ):
                return [tree_map(lowercase_      ,		lowercase_      ,		lowercase_  ) for x in tree]
         elif isinstance(lowercase_      ,		lowercase_  ):
                return tuple(tree_map(lowercase_      ,		lowercase_      ,		lowercase_  ) for x in tree  )
         elif isinstance(lowercase_      ,		lowercase_  ):
                return fn(lowercase_  )
         else:
                print(type(lowercase_  )  )
                raise ValueError('''Not supported'''  )
  lowerCAmelCase_   =   partial(tree_map, leaf_type=torch.Tensor)
  
  
  
  
  
  
  