code: 
  
  
  import torch
  
  from diffusers import HeunDiscreteScheduler
  from diffusers.utils import torch_device
  
  from .test_schedulers import SchedulerCommonTest
  
  
  
  
  
  
  
  class 					__lowercase					(       a_     ):
  
  
  
  		"""simple docstring"""
  
  		UpperCamelCase    :				List[Any] 					=		(HeunDiscreteScheduler,)
  		UpperCamelCase    :				Any 					=		1_0
  
  
  
  
  
  
  
  		def 				__A      (   self		,			**A  )     ->   Tuple:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     {
  					    """num_train_timesteps""": 11_00,
  					    """beta_start""": 0.0001,
  					    """beta_end""": 0.02,
  					    """beta_schedule""": """linear""",
  					}
  
  					config.update(**A  )
  					return config
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   int:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					for timesteps in [10, 50, 1_00, 10_00]:
  								self.check_over_configs(num_train_timesteps=A  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   int:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					for beta_start, beta_end in zip([0.00001, 0.0001, 0.001]		,			[0.0002, 0.002, 0.02]  ):
  								self.check_over_configs(beta_start=A		,			beta_end=A  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   int:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					for schedule in ["linear", "scaled_linear", "exp"]:
  								self.check_over_configs(beta_schedule=A  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   Tuple:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					for clip_sample_range in [1.0, 2.0, 3.0]:
  								self.check_over_configs(clip_sample_range=A		,			clip_sample=A  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   Tuple:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					for prediction_type in ["epsilon", "v_prediction", "sample"]:
  								self.check_over_configs(prediction_type=A  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   Any:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     self.scheduler_classes[0]
  					lowerCamelCase								=     self.get_scheduler_config()
  					lowerCamelCase								=     scheduler_class(**A  )
  
  					scheduler.set_timesteps(self.num_inference_steps  )
  
  					lowerCamelCase								=     self.dummy_model()
  					lowerCamelCase								=     self.dummy_sample_deter * scheduler.init_noise_sigma
  					lowerCamelCase								=     sample.to(A  )
  
  					for i, t in enumerate(scheduler.timesteps  ):
  								lowerCamelCase								=     scheduler.scale_model_input(A		,			A  )
  
  								lowerCamelCase								=     model(A		,			A  )
  
  								lowerCamelCase								=     scheduler.step(A		,			A		,			A  )
  								lowerCamelCase								=     output.prev_sample
  
  					lowerCamelCase								=     torch.sum(torch.abs(A  )  )
  					lowerCamelCase								=     torch.mean(torch.abs(A  )  )
  
  					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  )     ->   Any:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     self.scheduler_classes[0]
  					lowerCamelCase								=     self.get_scheduler_config(prediction_type="""v_prediction"""  )
  					lowerCamelCase								=     scheduler_class(**A  )
  
  					scheduler.set_timesteps(self.num_inference_steps  )
  
  					lowerCamelCase								=     self.dummy_model()
  					lowerCamelCase								=     self.dummy_sample_deter * scheduler.init_noise_sigma
  					lowerCamelCase								=     sample.to(A  )
  
  					for i, t in enumerate(scheduler.timesteps  ):
  								lowerCamelCase								=     scheduler.scale_model_input(A		,			A  )
  
  								lowerCamelCase								=     model(A		,			A  )
  
  								lowerCamelCase								=     scheduler.step(A		,			A		,			A  )
  								lowerCamelCase								=     output.prev_sample
  
  					lowerCamelCase								=     torch.sum(torch.abs(A  )  )
  					lowerCamelCase								=     torch.mean(torch.abs(A  )  )
  
  					if torch_device in ["cpu", "mps"]:
  								assert abs(result_sum.item() - 4.6_9_3_4e-0_7  ) < 1e-2
  								assert abs(result_mean.item() - 6.1_1_1_2e-1_0  ) < 1e-3
  					else:
  								# CUDA
  								assert abs(result_sum.item() - 4.6_9_3_4_2_8_6_5_0_1_7_0_9_7_2e-0_7  ) < 1e-2
  								assert abs(result_mean.item() - 0.0002  ) < 1e-3
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   Any:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     self.scheduler_classes[0]
  					lowerCamelCase								=     self.get_scheduler_config()
  					lowerCamelCase								=     scheduler_class(**A  )
  
  					scheduler.set_timesteps(self.num_inference_steps		,			device=A  )
  
  					lowerCamelCase								=     self.dummy_model()
  					lowerCamelCase								=     self.dummy_sample_deter.to(A  ) * scheduler.init_noise_sigma
  
  					for t in scheduler.timesteps:
  								lowerCamelCase								=     scheduler.scale_model_input(A		,			A  )
  
  								lowerCamelCase								=     model(A		,			A  )
  
  								lowerCamelCase								=     scheduler.step(A		,			A		,			A  )
  								lowerCamelCase								=     output.prev_sample
  
  					lowerCamelCase								=     torch.sum(torch.abs(A  )  )
  					lowerCamelCase								=     torch.mean(torch.abs(A  )  )
  
  					if str(A  ).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(A  ).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  )     ->   Any:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     self.scheduler_classes[0]
  					lowerCamelCase								=     self.get_scheduler_config()
  					lowerCamelCase								=     scheduler_class(**A		,			use_karras_sigmas=A  )
  
  					scheduler.set_timesteps(self.num_inference_steps		,			device=A  )
  
  					lowerCamelCase								=     self.dummy_model()
  					lowerCamelCase								=     self.dummy_sample_deter.to(A  ) * scheduler.init_noise_sigma
  					lowerCamelCase								=     sample.to(A  )
  
  					for t in scheduler.timesteps:
  								lowerCamelCase								=     scheduler.scale_model_input(A		,			A  )
  
  								lowerCamelCase								=     model(A		,			A  )
  
  								lowerCamelCase								=     scheduler.step(A		,			A		,			A  )
  								lowerCamelCase								=     output.prev_sample
  
  					lowerCamelCase								=     torch.sum(torch.abs(A  )  )
  					lowerCamelCase								=     torch.mean(torch.abs(A  )  )
  
  					assert abs(result_sum.item() - 0.00015  ) < 1e-2
  					assert abs(result_mean.item() - 1.9_8_6_9_5_5_4_5_3_5_0_3_4_6_9_5e-0_7  ) < 1e-2
  
  
style_context: 
  
  
  from __future__ import annotations
  
  from collections.abc import Callable
  from typing import Generic, TypeVar
  
  UpperCAmelCase      :						List[str]    =		TypeVar("T")
  UpperCAmelCase      :						Dict    =		TypeVar("U")
  
  
  
  
  
  
  
  class 					__lowercase					(       Generic[T, U]     ):
  
  
  
  		"""simple docstring"""
  
  		def __init__(   self		,			A		,			A  )     ->   Any:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     key
  					lowerCamelCase								=     val
  					lowerCamelCase								=     0
  					lowerCamelCase								=     None
  					lowerCamelCase								=     None
  
  
  
  
  
  
  
  		def __repr__(   self  )     ->   str:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					return "Node: key: {}, val: {}, freq: {}, has next: {}, has prev: {}".format(
  					    self.key		,			self.val		,			self.freq		,			self.next is not None		,			self.prev is not None  )
  
  
  
  
  
  
  
  class 					__lowercase					(       Generic[T, U]     ):
  
  
  
  		"""simple docstring"""
  
  		def __init__(   self  )     ->   None:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     DoubleLinkedListNode(A		,			A  )
  					lowerCamelCase								=     DoubleLinkedListNode(A		,			A  )
  					lowerCamelCase		,		lowerCamelCase								=     self.rear, self.head
  
  
  
  
  
  
  
  		def __repr__(   self  )     ->   str:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     ["""DoubleLinkedList"""]
  					lowerCamelCase								=     self.head
  					while node.next is not None:
  								rep.append(str(A  )  )
  								lowerCamelCase								=     node.next
  					rep.append(str(self.rear  )  )
  					return ",\n    ".join(A  )
  
  
  
  
  
  
  
  		def 				__A      (   self		,			A  )     ->   None:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     self.rear.prev
  
  					# All nodes other than self.head are guaranteed to have non-None previous
  					assert previous is not None
  
  					lowerCamelCase								=     node
  					lowerCamelCase								=     previous
  					lowerCamelCase								=     node
  					lowerCamelCase								=     self.rear
  					node.freq += 1
  					self._position_node(A  )
  
  
  
  
  
  
  
  		def 				__A      (   self		,			A  )     ->   None:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					while node.prev is not None and node.prev.freq > node.freq:
  								# swap node with previous node
  								lowerCamelCase								=     node.prev
  
  								lowerCamelCase								=     previous_node.prev
  								lowerCamelCase								=     node.prev
  								lowerCamelCase								=     previous_node
  								lowerCamelCase								=     node
  
  
  
  
  
  
  
  		def 				__A      (   self		,			A  )     ->   DoubleLinkedListNode[T, U] | None:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					if node.prev is None or node.next is None:
  								return None
  
  					lowerCamelCase								=     node.next
  					lowerCamelCase								=     node.prev
  					lowerCamelCase								=     None
  					lowerCamelCase								=     None
  					return node
  
  
  
  
  
  
  
  class 					__lowercase					(       Generic[T, U]     ):
  
  
  
  		"""simple docstring"""
  
  		UpperCamelCase    :				dict[Callable[[T], U], LFUCache[T, U]] 					=		{}
  
  
  
  
  
  
  
  		def __init__(   self		,			A  )     ->   Union[str, Any]:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     DoubleLinkedList()
  					lowerCamelCase								=     capacity
  					lowerCamelCase								=     0
  					lowerCamelCase								=     0
  					lowerCamelCase								=     0
  					lowerCamelCase								=     {}
  
  
  
  
  
  
  
  		def __repr__(   self  )     ->   str:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					return (
  					    F'CacheInfo(hits={self.hits}, misses={self.miss}, '
  					    F'capacity={self.capacity}, current_size={self.num_keys})'
  					)
  
  
  
  
  
  
  
  		def __contains__(   self		,			A  )     ->   bool:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					return key in self.cache
  
  
  
  
  
  
  
  		def 				__A      (   self		,			A  )     ->   U | None:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					if key in self.cache:
  								self.hits += 1
  								lowerCamelCase								=     self.cache[key]
  								lowerCamelCase								=     self.list.remove(self.cache[key]  )
  								assert node == value_node
  
  								# node is guaranteed not None because it is in self.cache
  								assert node is not None
  								self.list.add(A  )
  								return node.val
  					self.miss += 1
  					return None
  
  
  
  
  
  
  
  		def 				__A      (   self		,			A		,			A  )     ->   None:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					if key not in self.cache:
  								if self.num_keys >= self.capacity:
  											# delete first node when over capacity
  											lowerCamelCase								=     self.list.head.next
  
  											# guaranteed to have a non-None first node when num_keys > 0
  											# explain to type checker via assertions
  											assert first_node is not None
  											assert first_node.key is not None
  											assert self.list.remove(A  ) is not None
  											# first_node guaranteed to be in list
  
  											del self.cache[first_node.key]
  											self.num_keys -= 1
  								lowerCamelCase								=     DoubleLinkedListNode(A		,			A  )
  								self.list.add(self.cache[key]  )
  								self.num_keys += 1
  
  					else:
  								lowerCamelCase								=     self.list.remove(self.cache[key]  )
  								assert node is not None  # node guaranteed to be in list
  								lowerCamelCase								=     value
  								self.list.add(A  )
  
  
  
  
  
  
  
  		@classmethod
  		def 				__A      (   cls		,			A = 1_28  )     ->   Callable[[Callable[[T], U]], Callable[..., U]]:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					def cache_decorator_inner(A  ) -> Callable[..., U]:
  								def cache_decorator_wrapper(*A  ) -> U:
  											if func not in cls.decorator_function_to_instance_map:
  														lowerCamelCase								=     LFUCache(A  )
  
  											lowerCamelCase								=     cls.decorator_function_to_instance_map[func].get(args[0]  )
  											if result is None:
  														lowerCamelCase								=     func(*A  )
  														cls.decorator_function_to_instance_map[func].put(args[0]		,			A  )
  											return result
  
  								def cache_info() -> LFUCache[T, U]:
  											return cls.decorator_function_to_instance_map[func]
  
  								setattr(A		,			"""cache_info"""		,			A  )  # noqa: B010
  
  								return cache_decorator_wrapper
  
  					return cache_decorator_inner
  
  
  if __name__ == "__main__":
  		import doctest
  
  		doctest.testmod()
  
  