
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 		lowercase_							(							tf.keras.layers.Layer					):

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




        """simple docstring"""


        super().__init__(**__UpperCamelCase  )
        UpperCamelCase_											=							kernel_size // 2
        UpperCamelCase_											=							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_											=							tf.keras.layers.BatchNormalization(epsilon=1e-5  ,						momentum=0.9  ,						name="""normalization"""  )
        UpperCamelCase_											=							ACTaFN[activation] if activation is not None else tf.keras.layers.Activation("""linear"""  )

 def lowerCamelCase_					(   self  ,						__UpperCamelCase  ):




        """simple docstring"""


        UpperCamelCase_											=							UpperCamelCase_											=							(self.pad_value, self.pad_value)
        UpperCamelCase_											=							tf.pad(__UpperCamelCase  ,						[(0, 0), height_pad, width_pad, (0, 0)]  )
        UpperCamelCase_											=							self.conv(__UpperCamelCase  )
        return hidden_state

 def lowerCamelCase_					(   self  ,						__UpperCamelCase  ,						__UpperCamelCase = False  ):




        """simple docstring"""


        UpperCamelCase_											=							self.convolution(__UpperCamelCase  )
        UpperCamelCase_											=							self.normalization(__UpperCamelCase  ,						training=__UpperCamelCase  )
        UpperCamelCase_											=							self.activation(__UpperCamelCase  )
        return hidden_state



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

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




        """simple docstring"""


        super().__init__(**__UpperCamelCase  )
        UpperCamelCase_											=							TFResNetConvLayer(
            config.embedding_size  ,						kernel_size=7  ,						stride=2  ,						activation=config.hidden_act  ,						name="""embedder"""  ,						)
        UpperCamelCase_											=							tf.keras.layers.MaxPoolaD(pool_size=3  ,						strides=2  ,						padding="""valid"""  ,						name="""pooler"""  )
        UpperCamelCase_											=							config.num_channels

 def lowerCamelCase_					(   self  ,						__UpperCamelCase  ,						__UpperCamelCase = False  ):




        """simple docstring"""


        UpperCamelCase_							,					UpperCamelCase_							,					UpperCamelCase_							,					UpperCamelCase_											=							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_											=							pixel_values
        UpperCamelCase_											=							self.embedder(__UpperCamelCase  )
        UpperCamelCase_											=							tf.pad(__UpperCamelCase  ,						[[0, 0], [1, 1], [1, 1], [0, 0]]  )
        UpperCamelCase_											=							self.pooler(__UpperCamelCase  )
        return hidden_state



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

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




        """simple docstring"""


        super().__init__(**__UpperCamelCase  )
        UpperCamelCase_											=							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_											=							tf.keras.layers.BatchNormalization(epsilon=1e-5  ,						momentum=0.9  ,						name="""normalization"""  )

 def lowerCamelCase_					(   self  ,						__UpperCamelCase  ,						__UpperCamelCase = False  ):




        """simple docstring"""


        UpperCamelCase_											=							x
        UpperCamelCase_											=							self.convolution(__UpperCamelCase  )
        UpperCamelCase_											=							self.normalization(__UpperCamelCase  ,						training=__UpperCamelCase  )
        return hidden_state



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

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




        """simple docstring"""


        super().__init__(**__UpperCamelCase  )
        UpperCamelCase_											=							in_channels != out_channels or stride != 1
        UpperCamelCase_											=							TFResNetConvLayer(__UpperCamelCase  ,						stride=__UpperCamelCase  ,						name="""layer.0"""  )
        UpperCamelCase_											=							TFResNetConvLayer(__UpperCamelCase  ,						activation=__UpperCamelCase  ,						name="""layer.1"""  )
        UpperCamelCase_											=							(
            TFResNetShortCut(__UpperCamelCase  ,						stride=__UpperCamelCase  ,						name="""shortcut"""  )
            if should_apply_shortcut
            else tf.keras.layers.Activation("""linear"""  ,						name="""shortcut"""  )
        )
        UpperCamelCase_											=							ACTaFN[activation]

 def lowerCamelCase_					(   self  ,						__UpperCamelCase  ,						__UpperCamelCase = False  ):




        """simple docstring"""


        UpperCamelCase_											=							hidden_state
        UpperCamelCase_											=							self.conva(__UpperCamelCase  ,						training=__UpperCamelCase  )
        UpperCamelCase_											=							self.conva(__UpperCamelCase  ,						training=__UpperCamelCase  )
        UpperCamelCase_											=							self.shortcut(__UpperCamelCase  ,						training=__UpperCamelCase  )
        hidden_state += residual
        UpperCamelCase_											=							self.activation(__UpperCamelCase  )
        return hidden_state



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

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




        """simple docstring"""


        super().__init__(**__UpperCamelCase  )
        UpperCamelCase_											=							in_channels != out_channels or stride != 1
        UpperCamelCase_											=							out_channels // reduction
        UpperCamelCase_											=							TFResNetConvLayer(__UpperCamelCase  ,						kernel_size=1  ,						name="""layer.0"""  )
        UpperCamelCase_											=							TFResNetConvLayer(__UpperCamelCase  ,						stride=__UpperCamelCase  ,						name="""layer.1"""  )
        UpperCamelCase_											=							TFResNetConvLayer(__UpperCamelCase  ,						kernel_size=1  ,						activation=__UpperCamelCase  ,						name="""layer.2"""  )
        UpperCamelCase_											=							(
            TFResNetShortCut(__UpperCamelCase  ,						stride=__UpperCamelCase  ,						name="""shortcut"""  )
            if should_apply_shortcut
            else tf.keras.layers.Activation("""linear"""  ,						name="""shortcut"""  )
        )
        UpperCamelCase_											=							ACTaFN[activation]

 def lowerCamelCase_					(   self  ,						__UpperCamelCase  ,						__UpperCamelCase = False  ):




        """simple docstring"""


        UpperCamelCase_											=							hidden_state
        UpperCamelCase_											=							self.conva(__UpperCamelCase  ,						training=__UpperCamelCase  )
        UpperCamelCase_											=							self.conva(__UpperCamelCase  ,						training=__UpperCamelCase  )
        UpperCamelCase_											=							self.conva(__UpperCamelCase  ,						training=__UpperCamelCase  )
        UpperCamelCase_											=							self.shortcut(__UpperCamelCase  ,						training=__UpperCamelCase  )
        hidden_state += residual
        UpperCamelCase_											=							self.activation(__UpperCamelCase  )
        return hidden_state



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

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




        """simple docstring"""


        super().__init__(**__UpperCamelCase  )

        UpperCamelCase_											=							TFResNetBottleNeckLayer if config.layer_type == """bottleneck""" else TFResNetBasicLayer

        UpperCamelCase_											=							[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_											=							layers

 def lowerCamelCase_					(   self  ,						__UpperCamelCase  ,						__UpperCamelCase = False  ):




        """simple docstring"""


        for layer in self.stage_layers:
               UpperCamelCase_											=							layer(__UpperCamelCase  ,						training=__UpperCamelCase  )
        return hidden_state



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

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




        """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_											=							[
            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 lowerCamelCase_					(   self  ,						__UpperCamelCase  ,						__UpperCamelCase = False  ,						__UpperCamelCase = True  ,						__UpperCamelCase = False  ,						):




        """simple docstring"""


        UpperCamelCase_											=							() if output_hidden_states else None

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

               UpperCamelCase_											=							stage_module(__UpperCamelCase  ,						training=__UpperCamelCase  )

        if output_hidden_states:
               UpperCamelCase_											=							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 		lowercase_							(							__SCREAMING_SNAKE_CASE					):
 A__    :					Any    =     ResNetConfig
 A__    :					Optional[Any]    =     """resnet"""
 A__    :					Tuple    =     """pixel_values"""

 @property
 def lowerCamelCase_					(   self  ):




        """simple docstring"""


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



_A							=       R'''
    This model is a TensorFlow
    [tf.keras.layers.Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) sub-class. Use it as a
    regular TensorFlow Module and refer to the TensorFlow documentation for all matter related to general usage and
    behavior.

    Parameters:
        config ([`ResNetConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.
'''


_A							=       R'''
    Args:
        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See
            [`ConvNextImageProcessor.__call__`] for details.

        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
'''

@keras_serializable
class 		lowercase_							(							tf.keras.layers.Layer					):
 A__    :					Optional[Any]    =     ResNetConfig

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




        """simple docstring"""


        super().__init__(**__UpperCamelCase  )
        UpperCamelCase_											=							config
        UpperCamelCase_											=							TFResNetEmbeddings(__UpperCamelCase  ,						name="""embedder"""  )
        UpperCamelCase_											=							TFResNetEncoder(__UpperCamelCase  ,						name="""encoder"""  )
        UpperCamelCase_											=							tf.keras.layers.GlobalAveragePoolingaD(keepdims=__UpperCamelCase  )

 @unpack_inputs
 def lowerCamelCase_					(   self  ,						__UpperCamelCase  ,						__UpperCamelCase = None  ,						__UpperCamelCase = None  ,						__UpperCamelCase = False  ,						):




        """simple docstring"""


        UpperCamelCase_											=							(
            output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
        )
        UpperCamelCase_											=							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_											=							tf.transpose(__UpperCamelCase  ,						perm=[0, 2, 3, 1]  )
        UpperCamelCase_											=							self.embedder(__UpperCamelCase  ,						training=__UpperCamelCase  )

        UpperCamelCase_											=							self.encoder(
            __UpperCamelCase  ,						output_hidden_states=__UpperCamelCase  ,						return_dict=__UpperCamelCase  ,						training=__UpperCamelCase  )

        UpperCamelCase_											=							encoder_outputs[0]

        UpperCamelCase_											=							self.pooler(__UpperCamelCase  )

        # Transpose all the outputs to the NCHW format
        # (batch_size, height, width, num_channels) -> (batch_size, num_channels, height, width)
        UpperCamelCase_											=							tf.transpose(__UpperCamelCase  ,						(0, 3, 1, 2)  )
        UpperCamelCase_											=							tf.transpose(__UpperCamelCase  ,						(0, 3, 1, 2)  )
        UpperCamelCase_											=							()
        for hidden_state in encoder_outputs[1:]:
               UpperCamelCase_											=							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_											=							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 		lowercase_							(							__SCREAMING_SNAKE_CASE					):

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




        """simple docstring"""


        super().__init__(__UpperCamelCase  ,						**__UpperCamelCase  )
        UpperCamelCase_											=							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 lowerCamelCase_					(   self  ,						__UpperCamelCase  ,						__UpperCamelCase = None  ,						__UpperCamelCase = None  ,						__UpperCamelCase = False  ,						):




        """simple docstring"""


        UpperCamelCase_											=							(
            output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
        )
        UpperCamelCase_											=							return_dict if return_dict is not None else self.config.use_return_dict

        UpperCamelCase_											=							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 		lowercase_							(							__SCREAMING_SNAKE_CASE				,						__SCREAMING_SNAKE_CASE					):

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




        """simple docstring"""


        super().__init__(__UpperCamelCase  ,						**__UpperCamelCase  )
        UpperCamelCase_											=							config.num_labels
        UpperCamelCase_											=							TFResNetMainLayer(__UpperCamelCase  ,						name="""resnet"""  )
        # classification head
        UpperCamelCase_											=							(
            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 lowerCamelCase_					(   self  ,						__UpperCamelCase  ):




        """simple docstring"""


        UpperCamelCase_											=							tf.keras.layers.Flatten()(__UpperCamelCase  )
        UpperCamelCase_											=							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 lowerCamelCase_					(   self  ,						__UpperCamelCase = None  ,						__UpperCamelCase = None  ,						__UpperCamelCase = None  ,						__UpperCamelCase = None  ,						__UpperCamelCase = False  ,						):




        """simple docstring"""


        UpperCamelCase_											=							return_dict if return_dict is not None else self.config.use_return_dict

        UpperCamelCase_											=							self.resnet(
            __UpperCamelCase  ,						output_hidden_states=__UpperCamelCase  ,						return_dict=__UpperCamelCase  ,						training=__UpperCamelCase  )

        UpperCamelCase_											=							outputs.pooler_output if return_dict else outputs[1]

        UpperCamelCase_											=							self.classifier(__UpperCamelCase  )

        UpperCamelCase_											=							None if labels is None else self.hf_compute_loss(__UpperCamelCase  ,						__UpperCamelCase  )

        if not return_dict:
               UpperCamelCase_											=							(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



