
"""simple docstring"""





from typing import Optional, Tuple, Union

import tensorflow as tf

from ...activations_tf import ACTaFN
from ...modeling_tf_outputs import (
    TFBaseModelOutputWithNoAttention,
    TFBaseModelOutputWithPoolingAndNoAttention,
    TFImageClassifierOutputWithNoAttention,
)
from ...modeling_tf_utils import TFPreTrainedModel, TFSequenceClassificationLoss, keras_serializable, unpack_inputs
from ...tf_utils import shape_list
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_resnet import ResNetConfig


_a									=				logging.get_logger(__name__)

# General docstring
_a									=				'ResNetConfig'

# Base docstring
_a									=				'microsoft/resnet-50'
_a									=				[1, 2_048, 7, 7]

# Image classification docstring
_a									=				'microsoft/resnet-50'
_a									=				'tiger cat'

_a									=				[
    'microsoft/resnet-50',
    # See all resnet models at https://huggingface.co/models?filter=resnet
]


class A_      (tf.keras.layers.Layer ):




  '''simple docstring'''







  def __init__(						self							,  lowercase_							,  lowercase_ = 3							,  lowercase_ = 1							,  lowercase_ = "relu"							,  **lowercase_    ):

     """simple docstring"""
     super().__init__(**__UpperCamelCase    )
     UpperCAmelCase_   :   Optional[Any]     	=       kernel_size // 2
     UpperCAmelCase_   :   int     	=       tf.keras.layers.ConvaD(
         __UpperCamelCase							,  kernel_size=__UpperCamelCase							,  strides=__UpperCamelCase							,  padding="valid"							,  use_bias=__UpperCamelCase							,  name="convolution"    )
     # Use same default momentum and epsilon as PyTorch equivalent
     UpperCAmelCase_   :   Tuple     	=       tf.keras.layers.BatchNormalization(epsilon=1E-5							,  momentum=0.9							,  name="normalization"    )
     UpperCAmelCase_   :   List[Any]     	=       ACTaFN[activation] if activation is not None else tf.keras.layers.Activation("linear"    )







  def 			UpperCamelCase__   (						self							,  lowercase_    ):

     """simple docstring"""
     UpperCAmelCase_   :   List[Any]     	=       (self.pad_value, self.pad_value)
     UpperCAmelCase_   :   List[Any]     	=       tf.pad(__UpperCamelCase							,  [(0, 0), height_pad, width_pad, (0, 0)]    )
     UpperCAmelCase_   :   Optional[int]     	=       self.conv(__UpperCamelCase    )
     return hidden_state







  def 			UpperCamelCase__   (						self							,  lowercase_							,  lowercase_ = False    ):

     """simple docstring"""
     UpperCAmelCase_   :   Optional[Any]     	=       self.convolution(__UpperCamelCase    )
     UpperCAmelCase_   :   List[str]     	=       self.normalization(__UpperCamelCase							,  training=__UpperCamelCase    )
     UpperCAmelCase_   :   Union[str, Any]     	=       self.activation(__UpperCamelCase    )
     return hidden_state




class A_      (tf.keras.layers.Layer ):




  '''simple docstring'''







  def __init__(						self							,  lowercase_							,  **lowercase_    ):

     """simple docstring"""
     super().__init__(**__UpperCamelCase    )
     UpperCAmelCase_   :   str     	=       TFResNetConvLayer(
         config.embedding_size							,  kernel_size=7							,  stride=2							,  activation=config.hidden_act							,  name="embedder"							,  )
     UpperCAmelCase_   :   Optional[int]     	=       tf.keras.layers.MaxPoolaD(pool_size=3							,  strides=2							,  padding="valid"							,  name="pooler"    )
     UpperCAmelCase_   :   str     	=       config.num_channels







  def 			UpperCamelCase__   (						self							,  lowercase_							,  lowercase_ = False    ):

     """simple docstring"""
     UpperCAmelCase_	,  UpperCAmelCase_	,  UpperCAmelCase_	,  UpperCAmelCase_   :   Optional[int]     	=       shape_list(__UpperCamelCase    )
     if tf.executing_eagerly() and num_channels != self.num_channels:
        raise ValueError(
            "Make sure that the channel dimension of the pixel values match with the one set in the configuration."    )
     UpperCAmelCase_   :   Optional[int]     	=       pixel_values
     UpperCAmelCase_   :   Dict     	=       self.embedder(__UpperCamelCase    )
     UpperCAmelCase_   :   Union[str, Any]     	=       tf.pad(__UpperCamelCase							,  [[0, 0], [1, 1], [1, 1], [0, 0]]    )
     UpperCAmelCase_   :   Optional[Any]     	=       self.pooler(__UpperCamelCase    )
     return hidden_state




class A_      (tf.keras.layers.Layer ):




  '''simple docstring'''







  def __init__(						self							,  lowercase_							,  lowercase_ = 2							,  **lowercase_    ):

     """simple docstring"""
     super().__init__(**__UpperCamelCase    )
     UpperCAmelCase_   :   int     	=       tf.keras.layers.ConvaD(
         __UpperCamelCase							,  kernel_size=1							,  strides=__UpperCamelCase							,  use_bias=__UpperCamelCase							,  name="convolution"    )
     # Use same default momentum and epsilon as PyTorch equivalent
     UpperCAmelCase_   :   Dict     	=       tf.keras.layers.BatchNormalization(epsilon=1E-5							,  momentum=0.9							,  name="normalization"    )







  def 			UpperCamelCase__   (						self							,  lowercase_							,  lowercase_ = False    ):

     """simple docstring"""
     UpperCAmelCase_   :   str     	=       x
     UpperCAmelCase_   :   List[str]     	=       self.convolution(__UpperCamelCase    )
     UpperCAmelCase_   :   Optional[int]     	=       self.normalization(__UpperCamelCase							,  training=__UpperCamelCase    )
     return hidden_state




class A_      (tf.keras.layers.Layer ):




  '''simple docstring'''







  def __init__(						self							,  lowercase_							,  lowercase_							,  lowercase_ = 1							,  lowercase_ = "relu"							,  **lowercase_    ):

     """simple docstring"""
     super().__init__(**__UpperCamelCase    )
     UpperCAmelCase_   :   int     	=       in_channels != out_channels or stride != 1
     UpperCAmelCase_   :   Union[str, Any]     	=       TFResNetConvLayer(__UpperCamelCase							,  stride=__UpperCamelCase							,  name="layer.0"    )
     UpperCAmelCase_   :   Dict     	=       TFResNetConvLayer(__UpperCamelCase							,  activation=__UpperCamelCase							,  name="layer.1"    )
     UpperCAmelCase_   :   Any     	=       (
         TFResNetShortCut(__UpperCamelCase							,  stride=__UpperCamelCase							,  name="shortcut"    )
         if should_apply_shortcut
         else tf.keras.layers.Activation("linear"							,  name="shortcut"    )
     )
     UpperCAmelCase_   :   Optional[int]     	=       ACTaFN[activation]







  def 			UpperCamelCase__   (						self							,  lowercase_							,  lowercase_ = False    ):

     """simple docstring"""
     UpperCAmelCase_   :   Dict     	=       hidden_state
     UpperCAmelCase_   :   int     	=       self.conva(__UpperCamelCase							,  training=__UpperCamelCase    )
     UpperCAmelCase_   :   Any     	=       self.conva(__UpperCamelCase							,  training=__UpperCamelCase    )
     UpperCAmelCase_   :   int     	=       self.shortcut(__UpperCamelCase							,  training=__UpperCamelCase    )
     hidden_state += residual
     UpperCAmelCase_   :   Any     	=       self.activation(__UpperCamelCase    )
     return hidden_state




class A_      (tf.keras.layers.Layer ):




  '''simple docstring'''







  def __init__(						self							,  lowercase_							,  lowercase_							,  lowercase_ = 1							,  lowercase_ = "relu"							,  lowercase_ = 4							,  **lowercase_							,  ):

     """simple docstring"""
     super().__init__(**__UpperCamelCase    )
     UpperCAmelCase_   :   List[str]     	=       in_channels != out_channels or stride != 1
     UpperCAmelCase_   :   str     	=       out_channels // reduction
     UpperCAmelCase_   :   List[str]     	=       TFResNetConvLayer(__UpperCamelCase							,  kernel_size=1							,  name="layer.0"    )
     UpperCAmelCase_   :   Dict     	=       TFResNetConvLayer(__UpperCamelCase							,  stride=__UpperCamelCase							,  name="layer.1"    )
     UpperCAmelCase_   :   List[Any]     	=       TFResNetConvLayer(__UpperCamelCase							,  kernel_size=1							,  activation=__UpperCamelCase							,  name="layer.2"    )
     UpperCAmelCase_   :   Optional[int]     	=       (
         TFResNetShortCut(__UpperCamelCase							,  stride=__UpperCamelCase							,  name="shortcut"    )
         if should_apply_shortcut
         else tf.keras.layers.Activation("linear"							,  name="shortcut"    )
     )
     UpperCAmelCase_   :   Optional[Any]     	=       ACTaFN[activation]







  def 			UpperCamelCase__   (						self							,  lowercase_							,  lowercase_ = False    ):

     """simple docstring"""
     UpperCAmelCase_   :   Dict     	=       hidden_state
     UpperCAmelCase_   :   List[str]     	=       self.conva(__UpperCamelCase							,  training=__UpperCamelCase    )
     UpperCAmelCase_   :   List[str]     	=       self.conva(__UpperCamelCase							,  training=__UpperCamelCase    )
     UpperCAmelCase_   :   List[str]     	=       self.conva(__UpperCamelCase							,  training=__UpperCamelCase    )
     UpperCAmelCase_   :   str     	=       self.shortcut(__UpperCamelCase							,  training=__UpperCamelCase    )
     hidden_state += residual
     UpperCAmelCase_   :   List[str]     	=       self.activation(__UpperCamelCase    )
     return hidden_state




class A_      (tf.keras.layers.Layer ):




  '''simple docstring'''







  def __init__(						self							,  lowercase_							,  lowercase_							,  lowercase_							,  lowercase_ = 2							,  lowercase_ = 2							,  **lowercase_    ):

     """simple docstring"""
     super().__init__(**__UpperCamelCase    )

     UpperCAmelCase_   :   Any     	=       TFResNetBottleNeckLayer if config.layer_type == "bottleneck" else TFResNetBasicLayer

     UpperCAmelCase_   :   str     	=       [layer(__UpperCamelCase							,  __UpperCamelCase							,  stride=__UpperCamelCase							,  activation=config.hidden_act							,  name="layers.0"    )]
     layers += [
         layer(__UpperCamelCase							,  __UpperCamelCase							,  activation=config.hidden_act							,  name=F"""layers.{i + 1}"""    )
         for i in range(depth - 1    )
     ]
     UpperCAmelCase_   :   Union[str, Any]     	=       layers







  def 			UpperCamelCase__   (						self							,  lowercase_							,  lowercase_ = False    ):

     """simple docstring"""


     for layer in self.stage_layers:
        UpperCAmelCase_   :   Union[str, Any]     	=       layer(__UpperCamelCase							,  training=__UpperCamelCase    )
     return hidden_state




class A_      (tf.keras.layers.Layer ):




  '''simple docstring'''







  def __init__(						self							,  lowercase_							,  **lowercase_    ):

     """simple docstring"""
     super().__init__(**__UpperCamelCase    )
     # based on `downsample_in_first_stage` the first layer of the first stage may or may not downsample the input
     UpperCAmelCase_   :   Dict     	=       [
         TFResNetStage(
             __UpperCamelCase							,  config.embedding_size							,  config.hidden_sizes[0]							,  stride=2 if config.downsample_in_first_stage else 1							,  depth=config.depths[0]							,  name="stages.0"							,  )
     ]
     for i, (in_channels, out_channels, depth) in enumerate(
         zip(config.hidden_sizes							,  config.hidden_sizes[1:]							,  config.depths[1:]    )    ):
        self.stages.append(TFResNetStage(__UpperCamelCase							,  __UpperCamelCase							,  __UpperCamelCase							,  depth=__UpperCamelCase							,  name=F"""stages.{i + 1}"""    )    )







  def 			UpperCamelCase__   (						self							,  lowercase_							,  lowercase_ = False							,  lowercase_ = True							,  lowercase_ = False							,  ):

     """simple docstring"""
     UpperCAmelCase_   :   List[str]     	=       () if output_hidden_states else None

     for stage_module in self.stages:
        if output_hidden_states:
           UpperCAmelCase_   :   str     	=       hidden_states + (hidden_state,)

        UpperCAmelCase_   :   Union[str, Any]     	=       stage_module(__UpperCamelCase							,  training=__UpperCamelCase    )

     if output_hidden_states:
        UpperCAmelCase_   :   str     	=       hidden_states + (hidden_state,)

     if not return_dict:
        return tuple(v for v in [hidden_state, hidden_states] if v is not None    )

     return TFBaseModelOutputWithNoAttention(last_hidden_state=__UpperCamelCase							,  hidden_states=__UpperCamelCase    )




class A_      (__SCREAMING_SNAKE_CASE ):




  '''simple docstring'''
  SCREAMING_SNAKE_CASE__     :		Any    	=						ResNetConfig
  SCREAMING_SNAKE_CASE__     :		Optional[Any]    	=						"""resnet"""
  SCREAMING_SNAKE_CASE__     :		Tuple    	=						"""pixel_values"""







  @property
  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 224, 224)							,  dtype=tf.floataa    )}




_a									=				R'\n    This model is a TensorFlow\n    [tf.keras.layers.Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) sub-class. Use it as a\n    regular TensorFlow Module and refer to the TensorFlow documentation for all matter related to general usage and\n    behavior.\n\n    Parameters:\n        config ([`ResNetConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.\n'


_a									=				R'\n    Args:\n        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`ConvNextImageProcessor.__call__`] for details.\n\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\n            more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n'


@keras_serializable
class A_      (tf.keras.layers.Layer ):




  '''simple docstring'''
  SCREAMING_SNAKE_CASE__     :		Optional[Any]    	=						ResNetConfig







  def __init__(						self							,  lowercase_							,  **lowercase_    ):

     """simple docstring"""
     super().__init__(**__UpperCamelCase    )
     UpperCAmelCase_   :   Dict     	=       config
     UpperCAmelCase_   :   str     	=       TFResNetEmbeddings(__UpperCamelCase							,  name="embedder"    )
     UpperCAmelCase_   :   Any     	=       TFResNetEncoder(__UpperCamelCase							,  name="encoder"    )
     UpperCAmelCase_   :   List[str]     	=       tf.keras.layers.GlobalAveragePoolingaD(keepdims=__UpperCamelCase    )







  @unpack_inputs
  def 			UpperCamelCase__   (						self							,  lowercase_							,  lowercase_ = None							,  lowercase_ = None							,  lowercase_ = False							,  ):

     """simple docstring"""
     UpperCAmelCase_   :   str     	=       (
         output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
     )
     UpperCAmelCase_   :   Dict     	=       return_dict if return_dict is not None else self.config.use_return_dict

     # TF 2.0 image layers can't use NCHW format when running on CPU.
     # We transpose to NHWC format and then transpose back after the full forward pass.
     # (batch_size, num_channels, height, width) -> (batch_size, height, width, num_channels)
     UpperCAmelCase_   :   List[Any]     	=       tf.transpose(__UpperCamelCase							,  perm=[0, 2, 3, 1]    )
     UpperCAmelCase_   :   Union[str, Any]     	=       self.embedder(__UpperCamelCase							,  training=__UpperCamelCase    )

     UpperCAmelCase_   :   int     	=       self.encoder(
         __UpperCamelCase							,  output_hidden_states=__UpperCamelCase							,  return_dict=__UpperCamelCase							,  training=__UpperCamelCase    )

     UpperCAmelCase_   :   Any     	=       encoder_outputs[0]

     UpperCAmelCase_   :   List[str]     	=       self.pooler(__UpperCamelCase    )

     # Transpose all the outputs to the NCHW format
     # (batch_size, height, width, num_channels) -> (batch_size, num_channels, height, width)
     UpperCAmelCase_   :   List[str]     	=       tf.transpose(__UpperCamelCase							,  (0, 3, 1, 2)    )
     UpperCAmelCase_   :   Union[str, Any]     	=       tf.transpose(__UpperCamelCase							,  (0, 3, 1, 2)    )
     UpperCAmelCase_   :   str     	=       ()
     for hidden_state in encoder_outputs[1:]:
        UpperCAmelCase_   :   Dict     	=       hidden_states + tuple(tf.transpose(__UpperCamelCase							,  (0, 3, 1, 2)    ) for h in hidden_state    )

     if not return_dict:
        return (last_hidden_state, pooled_output) + hidden_states

     UpperCAmelCase_   :   Dict     	=       hidden_states if output_hidden_states else None

     return TFBaseModelOutputWithPoolingAndNoAttention(
         last_hidden_state=__UpperCamelCase							,  pooler_output=__UpperCamelCase							,  hidden_states=__UpperCamelCase							,  )




@add_start_docstrings(
    """The bare ResNet model outputting raw features without any specific head on top."""							,__SCREAMING_SNAKE_CASE							,)
class A_      (__SCREAMING_SNAKE_CASE ):




  '''simple docstring'''







  def __init__(						self							,  lowercase_							,  **lowercase_    ):

     """simple docstring"""
     super().__init__(__UpperCamelCase							,  **__UpperCamelCase    )
     UpperCAmelCase_   :   Union[str, Any]     	=       TFResNetMainLayer(config=__UpperCamelCase							,  name="resnet"    )







  @add_start_docstrings_to_model_forward(__UpperCamelCase    )
  @add_code_sample_docstrings(
      checkpoint=_CHECKPOINT_FOR_DOC							,  output_type=__UpperCamelCase							,  config_class=_CONFIG_FOR_DOC							,  modality="vision"							,  expected_output=_EXPECTED_OUTPUT_SHAPE							,  )
  @unpack_inputs
  def 			UpperCamelCase__   (						self							,  lowercase_							,  lowercase_ = None							,  lowercase_ = None							,  lowercase_ = False							,  ):

     """simple docstring"""
     UpperCAmelCase_   :   Union[str, Any]     	=       (
         output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
     )
     UpperCAmelCase_   :   Optional[Any]     	=       return_dict if return_dict is not None else self.config.use_return_dict

     UpperCAmelCase_   :   str     	=       self.resnet(
         pixel_values=__UpperCamelCase							,  output_hidden_states=__UpperCamelCase							,  return_dict=__UpperCamelCase							,  training=__UpperCamelCase							,  )
     return resnet_outputs




@add_start_docstrings(
    """
    ResNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for
    ImageNet.
    """							,__SCREAMING_SNAKE_CASE							,)
class A_      (__SCREAMING_SNAKE_CASE							,__SCREAMING_SNAKE_CASE ):




  '''simple docstring'''







  def __init__(						self							,  lowercase_							,  **lowercase_    ):

     """simple docstring"""
     super().__init__(__UpperCamelCase							,  **__UpperCamelCase    )
     UpperCAmelCase_   :   Optional[Any]     	=       config.num_labels
     UpperCAmelCase_   :   Optional[Any]     	=       TFResNetMainLayer(__UpperCamelCase							,  name="resnet"    )
     # classification head
     UpperCAmelCase_   :   int     	=       (
         tf.keras.layers.Dense(config.num_labels							,  name="classifier.1"    )
         if config.num_labels > 0
         else tf.keras.layers.Activation("linear"							,  name="classifier.1"    )
     )







  def 			UpperCamelCase__   (						self							,  lowercase_    ):

     """simple docstring"""
     UpperCAmelCase_   :   int     	=       tf.keras.layers.Flatten()(__UpperCamelCase    )
     UpperCAmelCase_   :   Optional[Any]     	=       self.classifier_layer(__UpperCamelCase    )
     return logits







  @add_start_docstrings_to_model_forward(__UpperCamelCase    )
  @add_code_sample_docstrings(
      checkpoint=_IMAGE_CLASS_CHECKPOINT							,  output_type=__UpperCamelCase							,  config_class=_CONFIG_FOR_DOC							,  expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT							,  )
  @unpack_inputs
  def 			UpperCamelCase__   (						self							,  lowercase_ = None							,  lowercase_ = None							,  lowercase_ = None							,  lowercase_ = None							,  lowercase_ = False							,  ):

     """simple docstring"""
     UpperCAmelCase_   :   List[Any]     	=       return_dict if return_dict is not None else self.config.use_return_dict

     UpperCAmelCase_   :   Dict     	=       self.resnet(
         __UpperCamelCase							,  output_hidden_states=__UpperCamelCase							,  return_dict=__UpperCamelCase							,  training=__UpperCamelCase    )

     UpperCAmelCase_   :   Any     	=       outputs.pooler_output if return_dict else outputs[1]

     UpperCAmelCase_   :   Any     	=       self.classifier(__UpperCamelCase    )

     UpperCAmelCase_   :   Dict     	=       None if labels is None else self.hf_compute_loss(__UpperCamelCase							,  __UpperCamelCase    )

     if not return_dict:
        UpperCAmelCase_   :   List[Any]     	=       (logits,) + outputs[2:]
        return (loss,) + output if loss is not None else output

     return TFImageClassifierOutputWithNoAttention(loss=__UpperCamelCase							,  logits=__UpperCamelCase							,  hidden_states=outputs.hidden_states    )




import tempfile

import torch

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

from .test_schedulers import SchedulerCommonTest

class 		lowercase_							(							__SCREAMING_SNAKE_CASE					):
 A__    :					List[Any]    =     (DPMSolverMultistepScheduler,)
 A__    :					List[str]    =     (("""num_inference_steps""", 25),)

 def lowerCamelCase_					(   self  ,						**__UpperCamelCase  ):




        """simple docstring"""


        UpperCamelCase_											=							{
            """num_train_timesteps""": 1_0_0_0,
            """beta_start""": 0.0_001,
            """beta_end""": 0.02,
            """beta_schedule""": """linear""",
            """solver_order""": 2,
            """prediction_type""": """epsilon""",
            """thresholding""": False,
            """sample_max_value""": 1.0,
            """algorithm_type""": """dpmsolver++""",
            """solver_type""": """midpoint""",
            """lower_order_final""": False,
            """lambda_min_clipped""": -float("""inf"""  ),
            """variance_type""": None,
        }

        config.update(**__UpperCamelCase  )
        return config

 def lowerCamelCase_					(   self  ,						__UpperCamelCase=0  ,						**__UpperCamelCase  ):




        """simple docstring"""


        UpperCamelCase_											=							dict(self.forward_default_kwargs  )
        UpperCamelCase_											=							kwargs.pop("""num_inference_steps"""  ,						__UpperCamelCase  )
        UpperCamelCase_											=							self.dummy_sample
        UpperCamelCase_											=							0.1 * sample
        UpperCamelCase_											=							[residual + 0.2, residual + 0.15, residual + 0.10]

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

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

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

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

 def lowerCamelCase_					(   self  ):




        """simple docstring"""


        pass

 def lowerCamelCase_					(   self  ,						__UpperCamelCase=0  ,						**__UpperCamelCase  ):




        """simple docstring"""


        UpperCamelCase_											=							dict(self.forward_default_kwargs  )
        UpperCamelCase_											=							kwargs.pop("""num_inference_steps"""  ,						__UpperCamelCase  )
        UpperCamelCase_											=							self.dummy_sample
        UpperCamelCase_											=							0.1 * sample
        UpperCamelCase_											=							[residual + 0.2, residual + 0.15, residual + 0.10]

        for scheduler_class in self.scheduler_classes:
               UpperCamelCase_											=							self.get_scheduler_config()
               UpperCamelCase_											=							scheduler_class(**__UpperCamelCase  )
               scheduler.set_timesteps(__UpperCamelCase  )

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

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

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

               UpperCamelCase_											=							scheduler.step(__UpperCamelCase  ,						__UpperCamelCase  ,						__UpperCamelCase  ,						**__UpperCamelCase  ).prev_sample
               UpperCamelCase_											=							new_scheduler.step(__UpperCamelCase  ,						__UpperCamelCase  ,						__UpperCamelCase  ,						**__UpperCamelCase  ).prev_sample

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

 def lowerCamelCase_					(   self  ,						__UpperCamelCase=None  ,						**__UpperCamelCase  ):




        """simple docstring"""


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

        UpperCamelCase_											=							1_0
        UpperCamelCase_											=							self.dummy_model()
        UpperCamelCase_											=							self.dummy_sample_deter
        scheduler.set_timesteps(__UpperCamelCase  )

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

        return sample

 def lowerCamelCase_					(   self  ):




        """simple docstring"""


        UpperCamelCase_											=							dict(self.forward_default_kwargs  )

        UpperCamelCase_											=							kwargs.pop("""num_inference_steps"""  ,						__UpperCamelCase  )

        for scheduler_class in self.scheduler_classes:
               UpperCamelCase_											=							self.get_scheduler_config()
               UpperCamelCase_											=							scheduler_class(**__UpperCamelCase  )

               UpperCamelCase_											=							self.dummy_sample
               UpperCamelCase_											=							0.1 * sample

               if num_inference_steps is not None and hasattr(__UpperCamelCase  ,						"""set_timesteps"""  ):
                      scheduler.set_timesteps(__UpperCamelCase  )
               elif num_inference_steps is not None and not hasattr(__UpperCamelCase  ,						"""set_timesteps"""  ):
                      UpperCamelCase_											=							num_inference_steps

               # copy over dummy past residuals (must be done after set_timesteps)
               UpperCamelCase_											=							[residual + 0.2, residual + 0.15, residual + 0.10]
               UpperCamelCase_											=							dummy_past_residuals[: scheduler.config.solver_order]

               UpperCamelCase_											=							scheduler.timesteps[5]
               UpperCamelCase_											=							scheduler.timesteps[6]

               UpperCamelCase_											=							scheduler.step(__UpperCamelCase  ,						__UpperCamelCase  ,						__UpperCamelCase  ,						**__UpperCamelCase  ).prev_sample
               UpperCamelCase_											=							scheduler.step(__UpperCamelCase  ,						__UpperCamelCase  ,						__UpperCamelCase  ,						**__UpperCamelCase  ).prev_sample

               self.assertEqual(output_a.shape  ,						sample.shape  )
               self.assertEqual(output_a.shape  ,						output_a.shape  )

 def lowerCamelCase_					(   self  ):




        """simple docstring"""


        for timesteps in [2_5, 5_0, 1_0_0, 9_9_9, 1_0_0_0]:
               self.check_over_configs(num_train_timesteps=__UpperCamelCase  )

 def lowerCamelCase_					(   self  ):




        """simple docstring"""


        self.check_over_configs(thresholding=__UpperCamelCase  )
        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=__UpperCamelCase  ,						prediction_type=__UpperCamelCase  ,						sample_max_value=__UpperCamelCase  ,						algorithm_type="""dpmsolver++"""  ,						solver_order=__UpperCamelCase  ,						solver_type=__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"""


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

 def lowerCamelCase_					(   self  ):




        """simple docstring"""


        self.check_over_configs(lower_order_final=__UpperCamelCase  )
        self.check_over_configs(lower_order_final=__UpperCamelCase  )

 def lowerCamelCase_					(   self  ):




        """simple docstring"""


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

 def lowerCamelCase_					(   self  ):




        """simple docstring"""


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

 def lowerCamelCase_					(   self  ):




        """simple docstring"""


        for num_inference_steps in [1, 2, 3, 5, 1_0, 5_0, 1_0_0, 9_9_9, 1_0_0_0]:
               self.check_over_forward(num_inference_steps=__UpperCamelCase  ,						time_step=0  )

 def lowerCamelCase_					(   self  ):




        """simple docstring"""


        UpperCamelCase_											=							self.full_loop()
        UpperCamelCase_											=							torch.mean(torch.abs(__UpperCamelCase  )  )

        assert abs(result_mean.item() - 0.3_301  ) < 1e-3

 def lowerCamelCase_					(   self  ):




        """simple docstring"""


        UpperCamelCase_											=							self.full_loop(thresholding=__UpperCamelCase  ,						dynamic_thresholding_ratio=0.87  ,						sample_max_value=0.5  )
        UpperCamelCase_											=							torch.mean(torch.abs(__UpperCamelCase  )  )

        assert abs(result_mean.item() - 1.1_364  ) < 1e-3

 def lowerCamelCase_					(   self  ):




        """simple docstring"""


        UpperCamelCase_											=							self.full_loop(prediction_type="""v_prediction"""  )
        UpperCamelCase_											=							torch.mean(torch.abs(__UpperCamelCase  )  )

        assert abs(result_mean.item() - 0.2_251  ) < 1e-3

 def lowerCamelCase_					(   self  ):




        """simple docstring"""


        UpperCamelCase_											=							self.full_loop(prediction_type="""v_prediction"""  ,						use_karras_sigmas=__UpperCamelCase  )
        UpperCamelCase_											=							torch.mean(torch.abs(__UpperCamelCase  )  )

        assert abs(result_mean.item() - 0.2_096  ) < 1e-3

 def lowerCamelCase_					(   self  ):




        """simple docstring"""


        UpperCamelCase_											=							DPMSolverMultistepScheduler(**self.get_scheduler_config()  )
        UpperCamelCase_											=							self.full_loop(scheduler=__UpperCamelCase  )
        UpperCamelCase_											=							torch.mean(torch.abs(__UpperCamelCase  )  )

        assert abs(result_mean.item() - 0.3_301  ) < 1e-3

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

        UpperCamelCase_											=							self.full_loop(scheduler=__UpperCamelCase  )
        UpperCamelCase_											=							torch.mean(torch.abs(__UpperCamelCase  )  )

        assert abs(result_mean.item() - 0.3_301  ) < 1e-3

 def lowerCamelCase_					(   self  ):




        """simple docstring"""


        UpperCamelCase_											=							self.scheduler_classes[0]
        UpperCamelCase_											=							self.get_scheduler_config(thresholding=__UpperCamelCase  ,						dynamic_thresholding_ratio=0  )
        UpperCamelCase_											=							scheduler_class(**__UpperCamelCase  )

        UpperCamelCase_											=							1_0
        UpperCamelCase_											=							self.dummy_model()
        UpperCamelCase_											=							self.dummy_sample_deter.half()
        scheduler.set_timesteps(__UpperCamelCase  )

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

        assert sample.dtype == torch.floataa

 def lowerCamelCase_					(   self  ,						**__UpperCamelCase  ):




        """simple docstring"""


        for scheduler_class in self.scheduler_classes:
               UpperCamelCase_											=							self.get_scheduler_config(**__UpperCamelCase  )
               UpperCamelCase_											=							scheduler_class(**__UpperCamelCase  )

               scheduler.set_timesteps(scheduler.config.num_train_timesteps  )
               assert len(scheduler.timesteps.unique()  ) == scheduler.num_inference_steps



