


"""simple docstring"""






import torch

from diffusers import KDPMaAncestralDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest


class 			SCREAMING_SNAKE_CASE_  (   _lowercase):




							'''simple docstring'''





							__magic_name__					:     Dict				  =  (KDPMaAncestralDiscreteScheduler,)
							__magic_name__					:     Union[str, Any]				  =  10




							def        UpperCAmelCase (						self	,					**lowerCamelCase__)   ->	int:







								'''simple docstring'''




								snake_case__  :						Dict		=      {
								    "num_train_timesteps": 1_100,
								    "beta_start": 0.00_01,
								    "beta_end": 0.02,
								    "beta_schedule": "linear",
								}

								config.update(**lowerCamelCase__)
								return config




							def        UpperCAmelCase (						self)   ->	Dict:







								'''simple docstring'''




								for timesteps in [10, 50, 100, 1_000]:
									self.check_over_configs(num_train_timesteps=lowerCamelCase__)




							def        UpperCAmelCase (						self)   ->	Tuple:







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




							def        UpperCAmelCase (						self)   ->	Dict:







								'''simple docstring'''




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




							def        UpperCAmelCase (						self)   ->	List[Any]:







								'''simple docstring'''




								if torch_device == "mps":
									return
								snake_case__  :						Tuple		=      self.scheduler_classes[0]
								snake_case__  :						List[Any]		=      self.get_scheduler_config()
								snake_case__  :						Tuple		=      scheduler_class(**lowerCamelCase__)

								scheduler.set_timesteps(self.num_inference_steps)

								snake_case__  :						Optional[int]		=      torch.manual_seed(0)

								snake_case__  :						Any		=      self.dummy_model()
								snake_case__  :						Tuple		=      self.dummy_sample_deter * scheduler.init_noise_sigma
								snake_case__  :						int		=      sample.to(lowerCamelCase__)

								for i, t in enumerate(scheduler.timesteps):
									snake_case__  :						List[str]		=      scheduler.scale_model_input(lowerCamelCase__	,					lowerCamelCase__)

									snake_case__  :						Any		=      model(lowerCamelCase__	,					lowerCamelCase__)

									snake_case__  :						Tuple		=      scheduler.step(lowerCamelCase__	,					lowerCamelCase__	,					lowerCamelCase__	,					generator=lowerCamelCase__)
									snake_case__  :						List[str]		=      output.prev_sample

								snake_case__  :						List[Any]		=      torch.sum(torch.abs(lowerCamelCase__))
								snake_case__  :						Tuple		=      torch.mean(torch.abs(lowerCamelCase__))

								assert abs(result_sum.item() - 1_38_49.38_77) < 1E-2
								assert abs(result_mean.item() - 18.03_31) < 5E-3




							def        UpperCAmelCase (						self)   ->	Union[str, Any]:







								'''simple docstring'''




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




							def        UpperCAmelCase (						self)   ->	Optional[Any]:







								'''simple docstring'''




								if torch_device == "mps":
									return
								snake_case__  :						int		=      self.scheduler_classes[0]
								snake_case__  :						Optional[int]		=      self.get_scheduler_config(prediction_type="v_prediction")
								snake_case__  :						int		=      scheduler_class(**lowerCamelCase__)

								scheduler.set_timesteps(self.num_inference_steps)

								snake_case__  :						List[Any]		=      self.dummy_model()
								snake_case__  :						str		=      self.dummy_sample_deter * scheduler.init_noise_sigma
								snake_case__  :						str		=      sample.to(lowerCamelCase__)

								snake_case__  :						Tuple		=      torch.manual_seed(0)

								for i, t in enumerate(scheduler.timesteps):
									snake_case__  :						Tuple		=      scheduler.scale_model_input(lowerCamelCase__	,					lowerCamelCase__)

									snake_case__  :						int		=      model(lowerCamelCase__	,					lowerCamelCase__)

									snake_case__  :						Union[str, Any]		=      scheduler.step(lowerCamelCase__	,					lowerCamelCase__	,					lowerCamelCase__	,					generator=lowerCamelCase__)
									snake_case__  :						List[str]		=      output.prev_sample

								snake_case__  :						Optional[Any]		=      torch.sum(torch.abs(lowerCamelCase__))
								snake_case__  :						List[Any]		=      torch.mean(torch.abs(lowerCamelCase__))

								assert abs(result_sum.item() - 3_28.99_70) < 1E-2
								assert abs(result_mean.item() - 0.42_84) < 1E-3







							def        UpperCAmelCase (						self)   ->	Optional[int]:







								'''simple docstring'''




								if torch_device == "mps":
									return
								snake_case__  :						str		=      self.scheduler_classes[0]
								snake_case__  :						Dict		=      self.get_scheduler_config()
								snake_case__  :						Dict		=      scheduler_class(**lowerCamelCase__)

								scheduler.set_timesteps(self.num_inference_steps	,					device=lowerCamelCase__)
								snake_case__  :						Tuple		=      torch.manual_seed(0)

								snake_case__  :						Tuple		=      self.dummy_model()
								snake_case__  :						int		=      self.dummy_sample_deter.to(lowerCamelCase__) * scheduler.init_noise_sigma

								for t in scheduler.timesteps:
									snake_case__  :						Dict		=      scheduler.scale_model_input(lowerCamelCase__	,					lowerCamelCase__)

									snake_case__  :						int		=      model(lowerCamelCase__	,					lowerCamelCase__)

									snake_case__  :						str		=      scheduler.step(lowerCamelCase__	,					lowerCamelCase__	,					lowerCamelCase__	,					generator=lowerCamelCase__)
									snake_case__  :						Dict		=      output.prev_sample

								snake_case__  :						Optional[int]		=      torch.sum(torch.abs(lowerCamelCase__))
								snake_case__  :						Optional[Any]		=      torch.mean(torch.abs(lowerCamelCase__))

								assert abs(result_sum.item() - 1_38_49.38_18) < 1E-1
								assert abs(result_mean.item() - 18.03_31) < 1E-3









"""simple docstring"""






import json

import requests

from .fetch_github_info import AUTHENTICATED_USER_ENDPOINT, fetch_github_info



def 			A__		(					_UpperCAmelCase    :      Optional[int]	)							->	Tuple:

	'''simple docstring'''


	class 			SCREAMING_SNAKE_CASE_  :




								'''simple docstring'''





								def __init__(						self	,					lowerCamelCase__)   ->	None:







									'''simple docstring'''




									assert isinstance(lowerCamelCase__	,					(bytes, str))
									snake_case__  :						int		=      content







								def        UpperCAmelCase (						self)   ->	Union[str, Any]:







									'''simple docstring'''




									return json.loads(self.content)

	def mock_response(*_UpperCAmelCase    :      str				,    **_UpperCAmelCase    :      Optional[int]	):
		assert args[0] == AUTHENTICATED_USER_ENDPOINT
		assert "Authorization" in kwargs["headers"]
		assert kwargs["headers"]["Authorization"].startswith("token "	)
		assert "Accept" in kwargs["headers"]
		return FakeResponse(b"{\"login\":\"test\",\"id\":1}"	)

	monkeypatch.setattr(_UpperCAmelCase				,    "get"				,    _UpperCAmelCase	)
	snake_case__  :						str		=      fetch_github_info("token"	)
	assert result["login"] == "test"
	assert result["id"] == 1





