
"""simple docstring"""




import torch

from diffusers import KDPMaDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest





class  snake_case     (							__lowercase   ):
							UpperCAmelCase__						     =      (KDPMaDiscreteScheduler,)
							UpperCAmelCase__						     =      10

							def _lowercase					(self       ,       **SCREAMING_SNAKE_CASE_    ):

									"""simple docstring"""







									SCREAMING_SNAKE_CASE_						 = {
									    '''num_train_timesteps''': 11_00,
									    '''beta_start''': 0.00_01,
									    '''beta_end''': 0.02,
									    '''beta_schedule''': '''linear''',
									}

									config.update(**SCREAMING_SNAKE_CASE_    )
									return config

							def _lowercase					(self    ):

									"""simple docstring"""







									for timesteps in [10, 50, 1_00, 10_00]:
											self.check_over_configs(num_train_timesteps=SCREAMING_SNAKE_CASE_    )

							def _lowercase					(self    ):

									"""simple docstring"""







									for beta_start, beta_end in zip([0.0_00_01, 0.00_01, 0.0_01]       ,       [0.00_02, 0.0_02, 0.02]    ):
											self.check_over_configs(beta_start=SCREAMING_SNAKE_CASE_       ,       beta_end=SCREAMING_SNAKE_CASE_    )

							def _lowercase					(self    ):

									"""simple docstring"""







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

							def _lowercase					(self    ):

									"""simple docstring"""







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

							def _lowercase					(self    ):

									"""simple docstring"""







									SCREAMING_SNAKE_CASE_						 = self.scheduler_classes[0]
									SCREAMING_SNAKE_CASE_						 = self.get_scheduler_config(prediction_type='''v_prediction'''    )
									SCREAMING_SNAKE_CASE_						 = scheduler_class(**SCREAMING_SNAKE_CASE_    )

									scheduler.set_timesteps(self.num_inference_steps    )

									SCREAMING_SNAKE_CASE_						 = self.dummy_model()
									SCREAMING_SNAKE_CASE_						 = self.dummy_sample_deter * scheduler.init_noise_sigma
									SCREAMING_SNAKE_CASE_						 = sample.to(SCREAMING_SNAKE_CASE_    )

									for i, t in enumerate(scheduler.timesteps    ):
											SCREAMING_SNAKE_CASE_						 = scheduler.scale_model_input(SCREAMING_SNAKE_CASE_       ,       SCREAMING_SNAKE_CASE_    )

											SCREAMING_SNAKE_CASE_						 = model(SCREAMING_SNAKE_CASE_       ,       SCREAMING_SNAKE_CASE_    )

											SCREAMING_SNAKE_CASE_						 = scheduler.step(SCREAMING_SNAKE_CASE_       ,       SCREAMING_SNAKE_CASE_       ,       SCREAMING_SNAKE_CASE_    )
											SCREAMING_SNAKE_CASE_						 = output.prev_sample

									SCREAMING_SNAKE_CASE_						 = torch.sum(torch.abs(SCREAMING_SNAKE_CASE_    )    )
									SCREAMING_SNAKE_CASE_						 = torch.mean(torch.abs(SCREAMING_SNAKE_CASE_    )    )

									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.00_02    ) < 1e-3

							def _lowercase					(self    ):

									"""simple docstring"""







									if torch_device == "mps":
											return
									SCREAMING_SNAKE_CASE_						 = self.scheduler_classes[0]
									SCREAMING_SNAKE_CASE_						 = self.get_scheduler_config()
									SCREAMING_SNAKE_CASE_						 = scheduler_class(**SCREAMING_SNAKE_CASE_    )

									scheduler.set_timesteps(self.num_inference_steps    )

									SCREAMING_SNAKE_CASE_						 = self.dummy_model()
									SCREAMING_SNAKE_CASE_						 = self.dummy_sample_deter * scheduler.init_noise_sigma
									SCREAMING_SNAKE_CASE_						 = sample.to(SCREAMING_SNAKE_CASE_    )

									for i, t in enumerate(scheduler.timesteps    ):
											SCREAMING_SNAKE_CASE_						 = scheduler.scale_model_input(SCREAMING_SNAKE_CASE_       ,       SCREAMING_SNAKE_CASE_    )

											SCREAMING_SNAKE_CASE_						 = model(SCREAMING_SNAKE_CASE_       ,       SCREAMING_SNAKE_CASE_    )

											SCREAMING_SNAKE_CASE_						 = scheduler.step(SCREAMING_SNAKE_CASE_       ,       SCREAMING_SNAKE_CASE_       ,       SCREAMING_SNAKE_CASE_    )
											SCREAMING_SNAKE_CASE_						 = output.prev_sample

									SCREAMING_SNAKE_CASE_						 = torch.sum(torch.abs(SCREAMING_SNAKE_CASE_    )    )
									SCREAMING_SNAKE_CASE_						 = torch.mean(torch.abs(SCREAMING_SNAKE_CASE_    )    )

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







							def _lowercase					(self    ):

									"""simple docstring"""







									if torch_device == "mps":
											return
									SCREAMING_SNAKE_CASE_						 = self.scheduler_classes[0]
									SCREAMING_SNAKE_CASE_						 = self.get_scheduler_config()
									SCREAMING_SNAKE_CASE_						 = scheduler_class(**SCREAMING_SNAKE_CASE_    )

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

									SCREAMING_SNAKE_CASE_						 = self.dummy_model()
									SCREAMING_SNAKE_CASE_						 = self.dummy_sample_deter.to(SCREAMING_SNAKE_CASE_    ) * scheduler.init_noise_sigma

									for t in scheduler.timesteps:
											SCREAMING_SNAKE_CASE_						 = scheduler.scale_model_input(SCREAMING_SNAKE_CASE_       ,       SCREAMING_SNAKE_CASE_    )

											SCREAMING_SNAKE_CASE_						 = model(SCREAMING_SNAKE_CASE_       ,       SCREAMING_SNAKE_CASE_    )

											SCREAMING_SNAKE_CASE_						 = scheduler.step(SCREAMING_SNAKE_CASE_       ,       SCREAMING_SNAKE_CASE_       ,       SCREAMING_SNAKE_CASE_    )
											SCREAMING_SNAKE_CASE_						 = output.prev_sample

									SCREAMING_SNAKE_CASE_						 = torch.sum(torch.abs(SCREAMING_SNAKE_CASE_    )    )
									SCREAMING_SNAKE_CASE_						 = 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() - 20.41_25    ) < 1e-2
											assert abs(result_mean.item() - 0.02_66    ) < 1e-3
									else:
											# CUDA
											assert abs(result_sum.item() - 20.41_25    ) < 1e-2
											assert abs(result_mean.item() - 0.02_66    ) < 1e-3

"""simple docstring"""




from __future__ import annotations



def        _lowerCamelCase ( __a,							__a    ):
		SCREAMING_SNAKE_CASE_						 = 0
		SCREAMING_SNAKE_CASE_						 = len(__a    ) - 1

		while i < j:
				if nums[i] + nums[j] == target:
						return [i, j]
				elif nums[i] + nums[j] < target:
						SCREAMING_SNAKE_CASE_						 = i + 1
				else:
						SCREAMING_SNAKE_CASE_						 = j - 1

		return []


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						print(f'''{two_pointer([2, 7, 11, 15], 9) = }''')