


'''simple docstring'''
import torch

from diffusers import KDPMaDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest
class        lowercase     (							__UpperCamelCase ):

		"""simple docstring"""

		_a   			=    (KDPMaDiscreteScheduler,)
		_a   			=    10




		def    lowerCAmelCase__    (		self   ,       **UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__       :Tuple							 =			{
							    """num_train_timesteps""": 1100,
							    """beta_start""": 0.0001,
							    """beta_end""": 0.02,
							    """beta_schedule""": """linear""",
							}

							config.update(**UpperCamelCase_							)
							return config




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							for timesteps in [10, 50, 100, 1000]:
												self.check_over_configs(num_train_timesteps=UpperCamelCase_							)




		def    lowerCAmelCase__    (		self							):

							'''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=UpperCamelCase_   ,       beta_end=UpperCamelCase_							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							for schedule in ["linear", "scaled_linear"]:
												self.check_over_configs(beta_schedule=UpperCamelCase_							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							for prediction_type in ["epsilon", "v_prediction"]:
												self.check_over_configs(prediction_type=UpperCamelCase_							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :Any							 =			self.scheduler_classes[0]
							UpperCamelCase__       :Tuple							 =			self.get_scheduler_config(prediction_type='''v_prediction'''							)
							UpperCamelCase__       :List[Any]							 =			scheduler_class(**UpperCamelCase_							)

							scheduler.set_timesteps(self.num_inference_steps							)

							UpperCamelCase__       :str							 =			self.dummy_model()
							UpperCamelCase__       :Optional[Any]							 =			self.dummy_sample_deter * scheduler.init_noise_sigma
							UpperCamelCase__       :List[str]							 =			sample.to(UpperCamelCase_							)

							for i, t in enumerate(scheduler.timesteps							):
												UpperCamelCase__       :Dict							 =			scheduler.scale_model_input(UpperCamelCase_   ,       UpperCamelCase_							)

												UpperCamelCase__       :Dict							 =			model(UpperCamelCase_   ,       UpperCamelCase_							)

												UpperCamelCase__       :Optional[Any]							 =			scheduler.step(UpperCamelCase_   ,       UpperCamelCase_   ,       UpperCamelCase_							)
												UpperCamelCase__       :List[str]							 =			output.prev_sample

							UpperCamelCase__       :List[str]							 =			torch.sum(torch.abs(UpperCamelCase_							)							)
							UpperCamelCase__       :Optional[Any]							 =			torch.mean(torch.abs(UpperCamelCase_							)							)

							if torch_device in ["cpu", "mps"]:
												assert abs(result_sum.item() - 4.69_34e-07							) < 1e-2
												assert abs(result_mean.item() - 6.11_12e-10							) < 1e-3
							else:
												# CUDA
												assert abs(result_sum.item() - 4.6_93_42_86_50_17_09_72e-07							) < 1e-2
												assert abs(result_mean.item() - 0.0002							) < 1e-3




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							if torch_device == "mps":
												return
							UpperCamelCase__       :Optional[int]							 =			self.scheduler_classes[0]
							UpperCamelCase__       :Tuple							 =			self.get_scheduler_config()
							UpperCamelCase__       :List[str]							 =			scheduler_class(**UpperCamelCase_							)

							scheduler.set_timesteps(self.num_inference_steps							)

							UpperCamelCase__       :int							 =			self.dummy_model()
							UpperCamelCase__       :Optional[Any]							 =			self.dummy_sample_deter * scheduler.init_noise_sigma
							UpperCamelCase__       :Any							 =			sample.to(UpperCamelCase_							)

							for i, t in enumerate(scheduler.timesteps							):
												UpperCamelCase__       :str							 =			scheduler.scale_model_input(UpperCamelCase_   ,       UpperCamelCase_							)

												UpperCamelCase__       :List[str]							 =			model(UpperCamelCase_   ,       UpperCamelCase_							)

												UpperCamelCase__       :List[Any]							 =			scheduler.step(UpperCamelCase_   ,       UpperCamelCase_   ,       UpperCamelCase_							)
												UpperCamelCase__       :Tuple							 =			output.prev_sample

							UpperCamelCase__       :Any							 =			torch.sum(torch.abs(UpperCamelCase_							)							)
							UpperCamelCase__       :Dict							 =			torch.mean(torch.abs(UpperCamelCase_							)							)

							if torch_device in ["cpu", "mps"]:
												assert abs(result_sum.item() - 20.4125							) < 1e-2
												assert abs(result_mean.item() - 0.0266							) < 1e-3
							else:
												# CUDA
												assert abs(result_sum.item() - 20.4125							) < 1e-2
												assert abs(result_mean.item() - 0.0266							) < 1e-3




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							if torch_device == "mps":
												return
							UpperCamelCase__       :str							 =			self.scheduler_classes[0]
							UpperCamelCase__       :Union[str, Any]							 =			self.get_scheduler_config()
							UpperCamelCase__       :Union[str, Any]							 =			scheduler_class(**UpperCamelCase_							)

							scheduler.set_timesteps(self.num_inference_steps   ,       device=UpperCamelCase_							)

							UpperCamelCase__       :List[str]							 =			self.dummy_model()
							UpperCamelCase__       :List[Any]							 =			self.dummy_sample_deter.to(UpperCamelCase_							) * scheduler.init_noise_sigma

							for t in scheduler.timesteps:
												UpperCamelCase__       :int							 =			scheduler.scale_model_input(UpperCamelCase_   ,       UpperCamelCase_							)

												UpperCamelCase__       :List[Any]							 =			model(UpperCamelCase_   ,       UpperCamelCase_							)

												UpperCamelCase__       :List[Any]							 =			scheduler.step(UpperCamelCase_   ,       UpperCamelCase_   ,       UpperCamelCase_							)
												UpperCamelCase__       :Union[str, Any]							 =			output.prev_sample

							UpperCamelCase__       :Union[str, Any]							 =			torch.sum(torch.abs(UpperCamelCase_							)							)
							UpperCamelCase__       :Dict							 =			torch.mean(torch.abs(UpperCamelCase_							)							)

							if str(UpperCamelCase_							).startswith('''cpu'''							):
												# The following sum varies between 148 and 156 on mps. Why?
												assert abs(result_sum.item() - 20.4125							) < 1e-2
												assert abs(result_mean.item() - 0.0266							) < 1e-3
							else:
												# CUDA
												assert abs(result_sum.item() - 20.4125							) < 1e-2
												assert abs(result_mean.item() - 0.0266							) < 1e-3










'''simple docstring'''
from __future__ import annotations

from typing import Any


def       a				(      __a       )  ->     None:



					'''simple docstring'''






					create_state_space_tree(__a			, []			, 0       )


def       a				(      __a			, __a			, __a       )  ->     None:



					'''simple docstring'''






					if index == len(__a       ):
										print(__a       )
										return

					create_state_space_tree(__a			, __a			, index + 1       )
					current_subsequence.append(sequence[index]       )
					create_state_space_tree(__a			, __a			, index + 1       )
					current_subsequence.pop()


if __name__ == "__main__":
		__snake_case											=					[3, 1, 2, 4]
		generate_all_subsequences(seq)

		seq.clear()
		seq.extend(['''A''', '''B''', '''C'''])
		generate_all_subsequences(seq)