
import inspect

import jax
import jax.lax as lax
import jax.numpy as jnp

from ..utils import add_start_docstrings
from ..utils.logging import get_logger


UpperCamelCase_   	=	get_logger(__name__)


UpperCamelCase_   	=	R"\n    Args:\n        input_ids (`jnp.ndarray` of shape `(batch_size, sequence_length)`):\n            Indices of input sequence tokens in the vocabulary.\n\n            Indices can be obtained using [`PreTrainedTokenizer`]. See [`PreTrainedTokenizer.encode`] and\n            [`PreTrainedTokenizer.__call__`] for details.\n\n            [What are input IDs?](../glossary#input-ids)\n        scores (`jnp.ndarray` of shape `(batch_size, config.vocab_size)`):\n            Prediction scores of a language modeling head. These can be logits for each vocabulary when not using beam\n            search or log softmax for each vocabulary token when using beam search\n        kwargs (`Dict[str, Any]`, *optional*):\n            Additional logits processor specific kwargs.\n\n    Return:\n        `jnp.ndarray` of shape `(batch_size, config.vocab_size)`: The processed prediction scores.\n\n"

class       a		:







							@add_start_docstrings(snake_case__ )
							def __call__(						self  :  List[str]      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  jnp.ndarray ):
								"""simple docstring"""







								raise NotImplementedError(
								    F"{self.__class__} is an abstract class. Only classes inheriting this class can be called." )

class       a		:







							@add_start_docstrings(snake_case__ )
							def __call__(						self  :  Optional[Any]      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  jnp.ndarray ):
								"""simple docstring"""







								raise NotImplementedError(
								    F"{self.__class__} is an abstract class. Only classes inheriting this class can be called." )

class       a		(   __UpperCAmelCase					):







							@add_start_docstrings(snake_case__ )
							def __call__(						self  :  Optional[int]      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  int      ,				**snake_case__  :  int ):
								"""simple docstring"""







								for processor in self:
									__lowerCAmelCase         =							inspect.signature(processor.__call__ ).parameters
									if len(snake_case__ ) > 3:
										if not all(arg in kwargs for arg in list(function_args.keys() )[2:] ):
											raise ValueError(
											    F"Make sure that all the required parameters: {list(function_args.keys() )} for "
											    F"{processor.__class__} are passed to the logits processor." )
										__lowerCAmelCase         =							processor(snake_case__      ,				snake_case__      ,				snake_case__      ,				**snake_case__ )
									else:
										__lowerCAmelCase         =							processor(snake_case__      ,				snake_case__      ,				snake_case__ )
								return scores

class       a		(   __UpperCAmelCase					):







							def __init__(						self  :  Union[str, Any]      ,				snake_case__  :  float ):
								"""simple docstring"""







								if not isinstance(snake_case__      ,				snake_case__ ) or not (temperature > 0):
									raise ValueError(F"`temperature` has to be a strictly positive float, but is {temperature}" )

								__lowerCAmelCase         =							temperature







							def __call__(						self  :  str      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  int ):
								"""simple docstring"""







								__lowerCAmelCase         =							scores / self.temperature
								return scores

class       a		(   __UpperCAmelCase					):







							def __init__(						self  :  Union[str, Any]      ,				snake_case__  :  float      ,				snake_case__  :  float = -float("Inf" )      ,				snake_case__  :  int = 1 ):
								"""simple docstring"""







								if not isinstance(snake_case__      ,				snake_case__ ) or (top_p < 0 or top_p > 1.0):
									raise ValueError(F"`top_p` has to be a float > 0 and < 1, but is {top_p}" )
								if not isinstance(snake_case__      ,				snake_case__ ) or (min_tokens_to_keep < 1):
									raise ValueError(F"`min_tokens_to_keep` has to be a positive integer, but is {min_tokens_to_keep}" )

								__lowerCAmelCase         =							top_p
								__lowerCAmelCase         =							filter_value
								__lowerCAmelCase         =							min_tokens_to_keep







							def __call__(						self  :  Optional[int]      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  int ):
								"""simple docstring"""







								__lowerCAmelCase   ,						__lowerCAmelCase         =							lax.top_k(snake_case__      ,				scores.shape[-1] )

								__lowerCAmelCase         =							jnp.full_like(snake_case__      ,				self.filter_value )
								__lowerCAmelCase         =							jax.nn.softmax(snake_case__      ,				axis=-1 ).cumsum(axis=-1 )
								__lowerCAmelCase         =							cumulative_probs < self.top_p

								# include the token that is higher than top_p as well
								__lowerCAmelCase         =							jnp.roll(snake_case__      ,				1 )
								score_mask |= score_mask.at[:, 0].set(snake_case__ )

								# min tokens to keep
								__lowerCAmelCase         =							score_mask.at[:, : self.min_tokens_to_keep].set(snake_case__ )

								__lowerCAmelCase         =							jnp.where(snake_case__      ,				snake_case__      ,				snake_case__ )
								__lowerCAmelCase         =							jax.lax.sort_key_val(snake_case__      ,				snake_case__ )[-1]

								return next_scores

class       a		(   __UpperCAmelCase					):







							def __init__(						self  :  int      ,				snake_case__  :  int      ,				snake_case__  :  float = -float("Inf" )      ,				snake_case__  :  int = 1 ):
								"""simple docstring"""







								if not isinstance(snake_case__      ,				snake_case__ ) or top_k <= 0:
									raise ValueError(F"`top_k` has to be a strictly positive integer, but is {top_k}" )

								__lowerCAmelCase         =							max(snake_case__      ,				snake_case__ )
								__lowerCAmelCase         =							filter_value







							def __call__(						self  :  Dict      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  int ):
								"""simple docstring"""







								__lowerCAmelCase   ,						__lowerCAmelCase         =							scores.shape
								__lowerCAmelCase         =							jnp.full(batch_size * vocab_size      ,				self.filter_value )

								__lowerCAmelCase         =							min(self.top_k      ,				scores.shape[-1] )  # Safety check
								__lowerCAmelCase   ,						__lowerCAmelCase         =							lax.top_k(snake_case__      ,				snake_case__ )
								__lowerCAmelCase         =							jnp.broadcast_to((jnp.arange(snake_case__ ) * vocab_size)[:, None]      ,				(batch_size, topk) ).flatten()
								__lowerCAmelCase         =							topk_scores.flatten()
								__lowerCAmelCase         =							topk_indices.flatten() + shift

								__lowerCAmelCase         =							next_scores_flat.at[topk_indices_flat].set(snake_case__ )
								__lowerCAmelCase         =							next_scores_flat.reshape(snake_case__      ,				snake_case__ )
								return next_scores

class       a		(   __UpperCAmelCase					):







							def __init__(						self  :  List[Any]      ,				snake_case__  :  int ):
								"""simple docstring"""







								__lowerCAmelCase         =							bos_token_id







							def __call__(						self  :  Optional[int]      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  int ):
								"""simple docstring"""







								__lowerCAmelCase         =							jnp.full(scores.shape      ,				-float("inf" ) )

								__lowerCAmelCase         =							1 - jnp.bool_(cur_len - 1 )

								__lowerCAmelCase         =							jnp.where(snake_case__      ,				new_scores.at[:, self.bos_token_id].set(0 )      ,				snake_case__ )

								return scores

class       a		(   __UpperCAmelCase					):







							def __init__(						self  :  Any      ,				snake_case__  :  int      ,				snake_case__  :  int ):
								"""simple docstring"""







								__lowerCAmelCase         =							max_length
								__lowerCAmelCase         =							eos_token_id







							def __call__(						self  :  Optional[int]      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  int ):
								"""simple docstring"""







								__lowerCAmelCase         =							jnp.full(scores.shape      ,				-float("inf" ) )

								__lowerCAmelCase         =							1 - jnp.bool_(cur_len - self.max_length + 1 )

								__lowerCAmelCase         =							jnp.where(snake_case__      ,				new_scores.at[:, self.eos_token_id].set(0 )      ,				snake_case__ )

								return scores

class       a		(   __UpperCAmelCase					):







							def __init__(						self  :  Tuple      ,				snake_case__  :  int      ,				snake_case__  :  int ):
								"""simple docstring"""







								if not isinstance(snake_case__      ,				snake_case__ ) or min_length < 0:
									raise ValueError(F"`min_length` has to be a positive integer, but is {min_length}" )

								if not isinstance(snake_case__      ,				snake_case__ ) or eos_token_id < 0:
									raise ValueError(F"`eos_token_id` has to be a positive integer, but is {eos_token_id}" )

								__lowerCAmelCase         =							min_length
								__lowerCAmelCase         =							eos_token_id







							def __call__(						self  :  List[Any]      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  int ):
								"""simple docstring"""







								__lowerCAmelCase         =							1 - jnp.clip(cur_len - self.min_length      ,				0      ,				1 )

								__lowerCAmelCase         =							jnp.where(snake_case__      ,				scores.at[:, self.eos_token_id].set(-float("inf" ) )      ,				snake_case__ )

								return scores

class       a		(   __UpperCAmelCase					):







							def __init__(						self  :  Optional[int]      ,				snake_case__  :  Union[str, Any]      ,				snake_case__  :  Optional[int] ):
								"""simple docstring"""







								__lowerCAmelCase         =							list(snake_case__ )
								__lowerCAmelCase         =							begin_index







							def __call__(						self  :  List[str]      ,				snake_case__  :  int      ,				snake_case__  :  Any      ,				snake_case__  :  int ):
								"""simple docstring"""







								__lowerCAmelCase         =							1 - jnp.bool_(cur_len - self.begin_index )

								__lowerCAmelCase         =							jnp.where(snake_case__      ,				scores.at[:, self.begin_suppress_tokens].set(-float("inf" ) )      ,				snake_case__ )

								return scores

class       a		(   __UpperCAmelCase					):







							def __init__(						self  :  Union[str, Any]      ,				snake_case__  :  list ):
								"""simple docstring"""







								__lowerCAmelCase         =							list(snake_case__ )







							def __call__(						self  :  int      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  int ):
								"""simple docstring"""







								__lowerCAmelCase         =							scores.at[..., self.suppress_tokens].set(-float("inf" ) )

								return scores

class       a		(   __UpperCAmelCase					):







							def __init__(						self  :  Any      ,				snake_case__  :  Tuple ):
								"""simple docstring"""







								__lowerCAmelCase         =							dict(snake_case__ )
								# Converts the dictionary of format {index: token} containing the tokens to be forced to an array, where the
								# index of the array corresponds to the index of the token to be forced, for XLA compatibility.
								# Indexes without forced tokens will have a negative value.
								__lowerCAmelCase         =							jnp.ones((max(force_token_map.keys() ) + 1)      ,				dtype=jnp.intaa ) * -1
								for index, token in force_token_map.items():
									if token is not None:
										__lowerCAmelCase         =							force_token_array.at[index].set(snake_case__ )
								__lowerCAmelCase         =							jnp.intaa(snake_case__ )







							def __call__(						self  :  Optional[int]      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  jnp.ndarray      ,				snake_case__  :  int ):
								"""simple docstring"""







								def _force_token(snake_case__  :  Dict ):
									__lowerCAmelCase         =							scores.shape[0]
									__lowerCAmelCase         =							self.force_token_array[generation_idx]

									__lowerCAmelCase         =							jnp.ones_like(snake_case__      ,				dtype=scores.dtype ) * -float("inf" )
									__lowerCAmelCase         =							jnp.zeros((batch_size, 1)      ,				dtype=scores.dtype )
									__lowerCAmelCase         =							lax.dynamic_update_slice(snake_case__      ,				snake_case__      ,				(0, current_token) )
									return new_scores

								__lowerCAmelCase         =							lax.cond(
								    cur_len >= self.force_token_array.shape[0]      ,				lambda: scores      ,				lambda: lax.cond(
								        self.force_token_array[cur_len] >= 0      ,				lambda: _force_token(snake_case__ )      ,				lambda: scores      ,				)      ,				)
								return scores

class       a		(   __UpperCAmelCase					):







							def __init__(						self  :  Any      ,				snake_case__  :  List[Any]      ,				snake_case__  :  Optional[int]      ,				snake_case__  :  Union[str, Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							generate_config.eos_token_id
								__lowerCAmelCase         =							generate_config.no_timestamps_token_id
								__lowerCAmelCase         =							generate_config.no_timestamps_token_id + 1

								__lowerCAmelCase         =							decoder_input_length + 1

								if generate_config.is_multilingual:
									# room for language token and task token
									self.begin_index += 2
								if hasattr(snake_case__      ,				"max_initial_timestamp_index" ):
									__lowerCAmelCase         =							generate_config.max_initial_timestamp_index
								else:
									__lowerCAmelCase         =							model_config.vocab_size
								if self.max_initial_timestamp_index is None:
									__lowerCAmelCase         =							model_config.vocab_size







							def __call__(						self  :  Tuple      ,				snake_case__  :  Dict      ,				snake_case__  :  Tuple      ,				snake_case__  :  int ):
								"""simple docstring"""







								__lowerCAmelCase         =							scores.at[:, self.no_timestamps_token_id].set(-float("inf" ) )

								def handle_pairs(snake_case__  :  Dict      ,				snake_case__  :  List[Any] ):
									__lowerCAmelCase         =							jnp.where((cur_len - self.begin_index) >= 1      ,				snake_case__      ,				snake_case__ )
									__lowerCAmelCase         =							jnp.where(
									    input_ids_k[cur_len - 1] >= self.timestamp_begin      ,				True and last_was_timestamp      ,				snake_case__      ,				)

									__lowerCAmelCase         =							jnp.where((cur_len - self.begin_index) < 2      ,				snake_case__      ,				snake_case__ )
									__lowerCAmelCase         =							jnp.where(
									    input_ids_k[cur_len - 2] >= self.timestamp_begin      ,				snake_case__      ,				snake_case__      ,				)

									return jnp.where(
									    snake_case__      ,				jnp.where(
									        penultimate_was_timestamp > 0      ,				scores_k.at[self.timestamp_begin :].set(-float("inf" ) )      ,				scores_k.at[: self.eos_token_id].set(-float("inf" ) )      ,				)      ,				snake_case__      ,				)

								__lowerCAmelCase         =							jax.vmap(snake_case__ )(snake_case__      ,				snake_case__ )

								__lowerCAmelCase         =							jnp.where(cur_len == self.begin_index      ,				snake_case__      ,				snake_case__ )
								__lowerCAmelCase         =							jnp.where(
								    self.max_initial_timestamp_index is not None      ,				True and apply_max_initial_timestamp      ,				snake_case__      ,				)

								__lowerCAmelCase         =							self.timestamp_begin + self.max_initial_timestamp_index

								__lowerCAmelCase         =							jnp.where(
								    snake_case__      ,				scores.at[:, last_allowed + 1 :].set(-float("inf" ) )      ,				snake_case__      ,				)

								# if sum of probability over timestamps is above any other token, sample timestamp
								__lowerCAmelCase         =							jax.nn.log_softmax(snake_case__      ,				axis=-1 )

								def handle_cumulative_probs(snake_case__  :  Union[str, Any]      ,				snake_case__  :  List[Any] ):
									__lowerCAmelCase         =							jax.nn.logsumexp(logprobs_k[self.timestamp_begin :]      ,				axis=-1 )
									__lowerCAmelCase         =							jnp.max(logprobs_k[: self.timestamp_begin] )
									return jnp.where(
									    timestamp_logprob > max_text_token_logprob      ,				scores_k.at[: self.timestamp_begin].set(-float("inf" ) )      ,				snake_case__      ,				)

								__lowerCAmelCase         =							jax.vmap(snake_case__ )(snake_case__      ,				snake_case__ )

								return scores








import tempfile

import torch

from diffusers import (
    DEISMultistepScheduler,
    DPMSolverMultistepScheduler,
    DPMSolverSinglestepScheduler,
    UniPCMultistepScheduler,
)

from .test_schedulers import SchedulerCommonTest

class       a		(   __UpperCAmelCase					):
							lowercase_		:						Dict   							=  (DPMSolverSinglestepScheduler,)
							lowercase_		:						Optional[Any]   							=  (('num_inference_steps', 25),)







							def       UpperCAmelCase__					(						self  :  Optional[Any]      ,				**snake_case__  :  Union[str, Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							{
								    "num_train_timesteps": 1_000,
								    "beta_start": 0.0_0_0_1,
								    "beta_end": 0.0_2,
								    "beta_schedule": "linear",
								    "solver_order": 2,
								    "prediction_type": "epsilon",
								    "thresholding": False,
								    "sample_max_value": 1.0,
								    "algorithm_type": "dpmsolver++",
								    "solver_type": "midpoint",
								    "lambda_min_clipped": -float("inf" ),
								    "variance_type": None,
								}

								config.update(**snake_case__ )
								return config







							def       UpperCAmelCase__					(						self  :  Any      ,				snake_case__  :  Tuple=0      ,				**snake_case__  :  Optional[Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							dict(self.forward_default_kwargs )
								__lowerCAmelCase         =							kwargs.pop("num_inference_steps"      ,				snake_case__ )
								__lowerCAmelCase         =							self.dummy_sample
								__lowerCAmelCase         =							0.1 * sample
								__lowerCAmelCase         =							[residual + 0.2, residual + 0.1_5, residual + 0.1_0]

								for scheduler_class in self.scheduler_classes:
									__lowerCAmelCase         =							self.get_scheduler_config(**snake_case__ )
									__lowerCAmelCase         =							scheduler_class(**snake_case__ )
									scheduler.set_timesteps(snake_case__ )
									# copy over dummy past residuals
									__lowerCAmelCase         =							dummy_past_residuals[: scheduler.config.solver_order]

									with tempfile.TemporaryDirectory() as tmpdirname:
										scheduler.save_config(snake_case__ )
										__lowerCAmelCase         =							scheduler_class.from_pretrained(snake_case__ )
										new_scheduler.set_timesteps(snake_case__ )
										# copy over dummy past residuals
										__lowerCAmelCase         =							dummy_past_residuals[: new_scheduler.config.solver_order]

									__lowerCAmelCase   ,						__lowerCAmelCase         =							sample, sample
									for t in range(snake_case__      ,				time_step + scheduler.config.solver_order + 1 ):
										__lowerCAmelCase         =							scheduler.step(snake_case__      ,				snake_case__      ,				snake_case__      ,				**snake_case__ ).prev_sample
										__lowerCAmelCase         =							new_scheduler.step(snake_case__      ,				snake_case__      ,				snake_case__      ,				**snake_case__ ).prev_sample

										assert torch.sum(torch.abs(output - new_output ) ) < 1E-5, "Scheduler outputs are not identical"







							def       UpperCAmelCase__					(						self  :  List[str] ):
								"""simple docstring"""







								pass







							def       UpperCAmelCase__					(						self  :  str      ,				snake_case__  :  Tuple=0      ,				**snake_case__  :  Tuple ):
								"""simple docstring"""







								__lowerCAmelCase         =							dict(self.forward_default_kwargs )
								__lowerCAmelCase         =							kwargs.pop("num_inference_steps"      ,				snake_case__ )
								__lowerCAmelCase         =							self.dummy_sample
								__lowerCAmelCase         =							0.1 * sample
								__lowerCAmelCase         =							[residual + 0.2, residual + 0.1_5, residual + 0.1_0]

								for scheduler_class in self.scheduler_classes:
									__lowerCAmelCase         =							self.get_scheduler_config()
									__lowerCAmelCase         =							scheduler_class(**snake_case__ )
									scheduler.set_timesteps(snake_case__ )

									# copy over dummy past residuals (must be after setting timesteps)
									__lowerCAmelCase         =							dummy_past_residuals[: scheduler.config.solver_order]

									with tempfile.TemporaryDirectory() as tmpdirname:
										scheduler.save_config(snake_case__ )
										__lowerCAmelCase         =							scheduler_class.from_pretrained(snake_case__ )
										# copy over dummy past residuals
										new_scheduler.set_timesteps(snake_case__ )

										# copy over dummy past residual (must be after setting timesteps)
										__lowerCAmelCase         =							dummy_past_residuals[: new_scheduler.config.solver_order]

									__lowerCAmelCase         =							scheduler.step(snake_case__      ,				snake_case__      ,				snake_case__      ,				**snake_case__ ).prev_sample
									__lowerCAmelCase         =							new_scheduler.step(snake_case__      ,				snake_case__      ,				snake_case__      ,				**snake_case__ ).prev_sample

									assert torch.sum(torch.abs(output - new_output ) ) < 1E-5, "Scheduler outputs are not identical"







							def       UpperCAmelCase__					(						self  :  Optional[Any]      ,				snake_case__  :  Optional[Any]=None      ,				**snake_case__  :  Optional[int] ):
								"""simple docstring"""







								if scheduler is None:
									__lowerCAmelCase         =							self.scheduler_classes[0]
									__lowerCAmelCase         =							self.get_scheduler_config(**snake_case__ )
									__lowerCAmelCase         =							scheduler_class(**snake_case__ )

								__lowerCAmelCase         =							self.scheduler_classes[0]
								__lowerCAmelCase         =							self.get_scheduler_config(**snake_case__ )
								__lowerCAmelCase         =							scheduler_class(**snake_case__ )

								__lowerCAmelCase         =							10
								__lowerCAmelCase         =							self.dummy_model()
								__lowerCAmelCase         =							self.dummy_sample_deter
								scheduler.set_timesteps(snake_case__ )

								for i, t in enumerate(scheduler.timesteps ):
									__lowerCAmelCase         =							model(snake_case__      ,				snake_case__ )
									__lowerCAmelCase         =							scheduler.step(snake_case__      ,				snake_case__      ,				snake_case__ ).prev_sample

								return sample







							def       UpperCAmelCase__					(						self  :  Union[str, Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							DPMSolverSinglestepScheduler(**self.get_scheduler_config() )
								__lowerCAmelCase         =							50
								__lowerCAmelCase         =							self.dummy_model()
								__lowerCAmelCase         =							self.dummy_sample_deter
								scheduler.set_timesteps(snake_case__ )

								# make sure that the first t is uneven
								for i, t in enumerate(scheduler.timesteps[3:] ):
									__lowerCAmelCase         =							model(snake_case__      ,				snake_case__ )
									__lowerCAmelCase         =							scheduler.step(snake_case__      ,				snake_case__      ,				snake_case__ ).prev_sample

								__lowerCAmelCase         =							torch.mean(torch.abs(snake_case__ ) )

								assert abs(result_mean.item() - 0.2_5_7_4 ) < 1E-3







							def       UpperCAmelCase__					(						self  :  List[str] ):
								"""simple docstring"""







								for timesteps in [25, 50, 100, 999, 1_000]:
									self.check_over_configs(num_train_timesteps=snake_case__ )







							def       UpperCAmelCase__					(						self  :  Optional[int] ):
								"""simple docstring"""







								__lowerCAmelCase         =							DPMSolverSinglestepScheduler(**self.get_scheduler_config() )
								__lowerCAmelCase         =							self.full_loop(scheduler=snake_case__ )
								__lowerCAmelCase         =							torch.mean(torch.abs(snake_case__ ) )

								assert abs(result_mean.item() - 0.2_7_9_1 ) < 1E-3

								__lowerCAmelCase         =							DEISMultistepScheduler.from_config(scheduler.config )
								__lowerCAmelCase         =							DPMSolverMultistepScheduler.from_config(scheduler.config )
								__lowerCAmelCase         =							UniPCMultistepScheduler.from_config(scheduler.config )
								__lowerCAmelCase         =							DPMSolverSinglestepScheduler.from_config(scheduler.config )

								__lowerCAmelCase         =							self.full_loop(scheduler=snake_case__ )
								__lowerCAmelCase         =							torch.mean(torch.abs(snake_case__ ) )

								assert abs(result_mean.item() - 0.2_7_9_1 ) < 1E-3







							def       UpperCAmelCase__					(						self  :  str ):
								"""simple docstring"""







								self.check_over_configs(thresholding=snake_case__ )
								for order in [1, 2, 3]:
									for solver_type in ["midpoint", "heun"]:
										for threshold in [0.5, 1.0, 2.0]:
											for prediction_type in ["epsilon", "sample"]:
												self.check_over_configs(
												    thresholding=snake_case__      ,				prediction_type=snake_case__      ,				sample_max_value=snake_case__      ,				algorithm_type="dpmsolver++"      ,				solver_order=snake_case__      ,				solver_type=snake_case__      ,				)







							def       UpperCAmelCase__					(						self  :  Union[str, Any] ):
								"""simple docstring"""







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







							def       UpperCAmelCase__					(						self  :  str ):
								"""simple docstring"""







								for algorithm_type in ["dpmsolver", "dpmsolver++"]:
									for solver_type in ["midpoint", "heun"]:
										for order in [1, 2, 3]:
											for prediction_type in ["epsilon", "sample"]:
												self.check_over_configs(
												    solver_order=snake_case__      ,				solver_type=snake_case__      ,				prediction_type=snake_case__      ,				algorithm_type=snake_case__      ,				)
												__lowerCAmelCase         =							self.full_loop(
												    solver_order=snake_case__      ,				solver_type=snake_case__      ,				prediction_type=snake_case__      ,				algorithm_type=snake_case__      ,				)
												assert not torch.isnan(snake_case__ ).any(), "Samples have nan numbers"







							def       UpperCAmelCase__					(						self  :  List[str] ):
								"""simple docstring"""







								self.check_over_configs(lower_order_final=snake_case__ )
								self.check_over_configs(lower_order_final=snake_case__ )







							def       UpperCAmelCase__					(						self  :  Dict ):
								"""simple docstring"""







								self.check_over_configs(lambda_min_clipped=-float("inf" ) )
								self.check_over_configs(lambda_min_clipped=-5.1 )







							def       UpperCAmelCase__					(						self  :  Any ):
								"""simple docstring"""







								self.check_over_configs(variance_type=snake_case__ )
								self.check_over_configs(variance_type="learned_range" )







							def       UpperCAmelCase__					(						self  :  List[Any] ):
								"""simple docstring"""







								for num_inference_steps in [1, 2, 3, 5, 10, 50, 100, 999, 1_000]:
									self.check_over_forward(num_inference_steps=snake_case__      ,				time_step=0 )







							def       UpperCAmelCase__					(						self  :  List[Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.full_loop()
								__lowerCAmelCase         =							torch.mean(torch.abs(snake_case__ ) )

								assert abs(result_mean.item() - 0.2_7_9_1 ) < 1E-3







							def       UpperCAmelCase__					(						self  :  List[str] ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.full_loop(use_karras_sigmas=snake_case__ )
								__lowerCAmelCase         =							torch.mean(torch.abs(snake_case__ ) )

								assert abs(result_mean.item() - 0.2_2_4_8 ) < 1E-3







							def       UpperCAmelCase__					(						self  :  List[str] ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.full_loop(prediction_type="v_prediction" )
								__lowerCAmelCase         =							torch.mean(torch.abs(snake_case__ ) )

								assert abs(result_mean.item() - 0.1_4_5_3 ) < 1E-3







							def       UpperCAmelCase__					(						self  :  Optional[Any] ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.full_loop(prediction_type="v_prediction"      ,				use_karras_sigmas=snake_case__ )
								__lowerCAmelCase         =							torch.mean(torch.abs(snake_case__ ) )

								assert abs(result_mean.item() - 0.0_6_4_9 ) < 1E-3







							def       UpperCAmelCase__					(						self  :  int ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.scheduler_classes[0]
								__lowerCAmelCase         =							self.get_scheduler_config(thresholding=snake_case__      ,				dynamic_thresholding_ratio=0 )
								__lowerCAmelCase         =							scheduler_class(**snake_case__ )

								__lowerCAmelCase         =							10
								__lowerCAmelCase         =							self.dummy_model()
								__lowerCAmelCase         =							self.dummy_sample_deter.half()
								scheduler.set_timesteps(snake_case__ )

								for i, t in enumerate(scheduler.timesteps ):
									__lowerCAmelCase         =							model(snake_case__      ,				snake_case__ )
									__lowerCAmelCase         =							scheduler.step(snake_case__      ,				snake_case__      ,				snake_case__ ).prev_sample

								assert sample.dtype == torch.floataa






