code: 
  '''simple docstring'''
  
  
  
  
  
  import tempfile
  
  import torch
  
  from diffusers import (
      DEISMultistepScheduler,
      DPMSolverMultistepScheduler,
      DPMSolverSinglestepScheduler,
      UniPCMultistepScheduler,
  )
  
  from .test_schedulers import SchedulerCommonTest
  
  
  
  
  
  
  class 						lowercase     (   UpperCAmelCase_):
        __lowercase 		=  (DPMSolverMultistepScheduler,)
        __lowercase 		=  (('''num_inference_steps''', 25),)
  
  
  
  
  
  
        def    A__(self ,  **a__					)       ->   Optional[Any]:
           SCREAMING_SNAKE_CASE__			:				Tuple       						= {
               '''num_train_timesteps''': 1_0_0_0,
               '''beta_start''': 0.00_01,
               '''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(**a__					)
           return config
  
  
  
  
  
  
        def    A__(self ,  a__=0 ,  **a__					)       ->   Dict:
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= dict(self.forward_default_kwargs					)
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= kwargs.pop('''num_inference_steps''' ,  a__					)
           SCREAMING_SNAKE_CASE__			:				Dict       						= self.dummy_sample
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= 0.1 * sample
           SCREAMING_SNAKE_CASE__			:				str       						= [residual + 0.2, residual + 0.15, residual + 0.10]
  
           for scheduler_class in self.scheduler_classes:
              SCREAMING_SNAKE_CASE__			:				int       						= self.get_scheduler_config(**a__					)
              SCREAMING_SNAKE_CASE__			:				List[str]       						= scheduler_class(**a__					)
              scheduler.set_timesteps(a__					)
              # copy over dummy past residuals
              SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= dummy_past_residuals[: scheduler.config.solver_order]
  
              with tempfile.TemporaryDirectory() as tmpdirname:
                 scheduler.save_config(a__					)
                 SCREAMING_SNAKE_CASE__			:				str       						= scheduler_class.from_pretrained(a__					)
                 new_scheduler.set_timesteps(a__					)
                 # copy over dummy past residuals
                 SCREAMING_SNAKE_CASE__			:				int       						= dummy_past_residuals[: new_scheduler.config.solver_order]
  
              SCREAMING_SNAKE_CASE__			:				str       						= sample, sample
              for t in range(a__ ,  time_step + scheduler.config.solver_order + 1					):
                 SCREAMING_SNAKE_CASE__			:				List[str]       						= scheduler.step(a__ ,  a__ ,  a__ ,  **a__					).prev_sample
                 SCREAMING_SNAKE_CASE__			:				List[str]       						= new_scheduler.step(a__ ,  a__ ,  a__ ,  **a__					).prev_sample
  
                 assert torch.sum(torch.abs(output - new_output					)					) < 1E-5, "Scheduler outputs are not identical"
  
  
  
  
  
  
        def    A__(self					)       ->   Optional[Any]:
           pass
  
  
  
  
  
  
        def    A__(self ,  a__=0 ,  **a__					)       ->   int:
           SCREAMING_SNAKE_CASE__			:				Tuple       						= dict(self.forward_default_kwargs					)
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= kwargs.pop('''num_inference_steps''' ,  a__					)
           SCREAMING_SNAKE_CASE__			:				Tuple       						= self.dummy_sample
           SCREAMING_SNAKE_CASE__			:				Any       						= 0.1 * sample
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= [residual + 0.2, residual + 0.15, residual + 0.10]
  
           for scheduler_class in self.scheduler_classes:
              SCREAMING_SNAKE_CASE__			:				Dict       						= self.get_scheduler_config()
              SCREAMING_SNAKE_CASE__			:				str       						= scheduler_class(**a__					)
              scheduler.set_timesteps(a__					)
  
              # copy over dummy past residuals (must be after setting timesteps)
              SCREAMING_SNAKE_CASE__			:				Tuple       						= dummy_past_residuals[: scheduler.config.solver_order]
  
              with tempfile.TemporaryDirectory() as tmpdirname:
                 scheduler.save_config(a__					)
                 SCREAMING_SNAKE_CASE__			:				List[Any]       						= scheduler_class.from_pretrained(a__					)
                 # copy over dummy past residuals
                 new_scheduler.set_timesteps(a__					)
  
                 # copy over dummy past residual (must be after setting timesteps)
                 SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= dummy_past_residuals[: new_scheduler.config.solver_order]
  
              SCREAMING_SNAKE_CASE__			:				str       						= scheduler.step(a__ ,  a__ ,  a__ ,  **a__					).prev_sample
              SCREAMING_SNAKE_CASE__			:				Dict       						= new_scheduler.step(a__ ,  a__ ,  a__ ,  **a__					).prev_sample
  
              assert torch.sum(torch.abs(output - new_output					)					) < 1E-5, "Scheduler outputs are not identical"
  
  
  
  
  
  
        def    A__(self ,  a__=None ,  **a__					)       ->   int:
           if scheduler is None:
              SCREAMING_SNAKE_CASE__			:				str       						= self.scheduler_classes[0]
              SCREAMING_SNAKE_CASE__			:				List[Any]       						= self.get_scheduler_config(**a__					)
              SCREAMING_SNAKE_CASE__			:				Any       						= scheduler_class(**a__					)
  
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= 1_0
           SCREAMING_SNAKE_CASE__			:				List[str]       						= self.dummy_model()
           SCREAMING_SNAKE_CASE__			:				str       						= self.dummy_sample_deter
           scheduler.set_timesteps(a__					)
  
           for i, t in enumerate(scheduler.timesteps					):
              SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= model(a__ ,  a__					)
              SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= scheduler.step(a__ ,  a__ ,  a__					).prev_sample
  
           return sample
  
  
  
  
  
  
        def    A__(self					)       ->   List[str]:
           SCREAMING_SNAKE_CASE__			:				List[Any]       						= dict(self.forward_default_kwargs					)
  
           SCREAMING_SNAKE_CASE__			:				int       						= kwargs.pop('''num_inference_steps''' ,  a__					)
  
           for scheduler_class in self.scheduler_classes:
              SCREAMING_SNAKE_CASE__			:				Dict       						= self.get_scheduler_config()
              SCREAMING_SNAKE_CASE__			:				Dict       						= scheduler_class(**a__					)
  
              SCREAMING_SNAKE_CASE__			:				Dict       						= self.dummy_sample
              SCREAMING_SNAKE_CASE__			:				Dict       						= 0.1 * sample
  
              if num_inference_steps is not None and hasattr(a__ ,  '''set_timesteps'''					):
                 scheduler.set_timesteps(a__					)
              elif num_inference_steps is not None and not hasattr(a__ ,  '''set_timesteps'''					):
                 SCREAMING_SNAKE_CASE__			:				Tuple       						= num_inference_steps
  
              # copy over dummy past residuals (must be done after set_timesteps)
              SCREAMING_SNAKE_CASE__			:				List[str]       						= [residual + 0.2, residual + 0.15, residual + 0.10]
              SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= dummy_past_residuals[: scheduler.config.solver_order]
  
              SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= scheduler.timesteps[5]
              SCREAMING_SNAKE_CASE__			:				List[Any]       						= scheduler.timesteps[6]
  
              SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= scheduler.step(a__ ,  a__ ,  a__ ,  **a__					).prev_sample
              SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= scheduler.step(a__ ,  a__ ,  a__ ,  **a__					).prev_sample
  
              self.assertEqual(output_a.shape ,  sample.shape					)
              self.assertEqual(output_a.shape ,  output_a.shape					)
  
  
  
  
  
  
        def    A__(self					)       ->   List[Any]:
           for timesteps in [2_5, 5_0, 1_0_0, 9_9_9, 1_0_0_0]:
              self.check_over_configs(num_train_timesteps=a__					)
  
  
  
  
  
  
        def    A__(self					)       ->   int:
           self.check_over_configs(thresholding=a__					)
           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=a__ ,  prediction_type=a__ ,  sample_max_value=a__ ,  algorithm_type='''dpmsolver++''' ,  solver_order=a__ ,  solver_type=a__ ,  )
  
  
  
  
  
  
        def    A__(self					)       ->   List[str]:
           for prediction_type in ["epsilon", "v_prediction"]:
              self.check_over_configs(prediction_type=a__					)
  
  
  
  
  
  
        def    A__(self					)       ->   int:
           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=a__ ,  solver_type=a__ ,  prediction_type=a__ ,  algorithm_type=a__ ,  )
                       SCREAMING_SNAKE_CASE__			:				Any       						= self.full_loop(
                           solver_order=a__ ,  solver_type=a__ ,  prediction_type=a__ ,  algorithm_type=a__ ,  )
                       assert not torch.isnan(a__					).any(), "Samples have nan numbers"
  
  
  
  
  
  
        def    A__(self					)       ->   Any:
           self.check_over_configs(lower_order_final=a__					)
           self.check_over_configs(lower_order_final=a__					)
  
  
  
  
  
  
        def    A__(self					)       ->   Optional[Any]:
           self.check_over_configs(lambda_min_clipped=-float('''inf'''					)					)
           self.check_over_configs(lambda_min_clipped=-5.1					)
  
  
  
  
  
  
        def    A__(self					)       ->   Optional[int]:
           self.check_over_configs(variance_type=a__					)
           self.check_over_configs(variance_type='''learned_range'''					)
  
  
  
  
  
  
        def    A__(self					)       ->   Union[str, Any]:
           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=a__ ,  time_step=0					)
  
  
  
  
  
  
        def    A__(self					)       ->   List[str]:
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= self.full_loop()
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= torch.mean(torch.abs(a__					)					)
  
           assert abs(result_mean.item() - 0.33_01					) < 1E-3
  
  
  
  
  
  
        def    A__(self					)       ->   List[str]:
           SCREAMING_SNAKE_CASE__			:				List[Any]       						= self.full_loop(thresholding=a__ ,  dynamic_thresholding_ratio=0.87 ,  sample_max_value=0.5					)
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= torch.mean(torch.abs(a__					)					)
  
           assert abs(result_mean.item() - 1.13_64					) < 1E-3
  
  
  
  
  
  
        def    A__(self					)       ->   Any:
           SCREAMING_SNAKE_CASE__			:				Optional[int]       						= self.full_loop(prediction_type='''v_prediction'''					)
           SCREAMING_SNAKE_CASE__			:				List[str]       						= torch.mean(torch.abs(a__					)					)
  
           assert abs(result_mean.item() - 0.22_51					) < 1E-3
  
  
  
  
  
  
        def    A__(self					)       ->   int:
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= self.full_loop(prediction_type='''v_prediction''' ,  use_karras_sigmas=a__					)
           SCREAMING_SNAKE_CASE__			:				int       						= torch.mean(torch.abs(a__					)					)
  
           assert abs(result_mean.item() - 0.20_96					) < 1E-3
  
  
  
  
  
  
        def    A__(self					)       ->   Optional[int]:
           # make sure that iterating over schedulers with same config names gives same results
           # for defaults
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= DPMSolverMultistepScheduler(**self.get_scheduler_config()					)
           SCREAMING_SNAKE_CASE__			:				List[str]       						= self.full_loop(scheduler=a__					)
           SCREAMING_SNAKE_CASE__			:				Dict       						= torch.mean(torch.abs(a__					)					)
  
           assert abs(result_mean.item() - 0.33_01					) < 1E-3
  
           SCREAMING_SNAKE_CASE__			:				Any       						= DPMSolverSinglestepScheduler.from_config(scheduler.config					)
           SCREAMING_SNAKE_CASE__			:				List[Any]       						= UniPCMultistepScheduler.from_config(scheduler.config					)
           SCREAMING_SNAKE_CASE__			:				str       						= DEISMultistepScheduler.from_config(scheduler.config					)
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= DPMSolverMultistepScheduler.from_config(scheduler.config					)
  
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= self.full_loop(scheduler=a__					)
           SCREAMING_SNAKE_CASE__			:				Tuple       						= torch.mean(torch.abs(a__					)					)
  
           assert abs(result_mean.item() - 0.33_01					) < 1E-3
  
  
  
  
  
  
        def    A__(self					)       ->   int:
           SCREAMING_SNAKE_CASE__			:				str       						= self.scheduler_classes[0]
           SCREAMING_SNAKE_CASE__			:				Dict       						= self.get_scheduler_config(thresholding=a__ ,  dynamic_thresholding_ratio=0					)
           SCREAMING_SNAKE_CASE__			:				str       						= scheduler_class(**a__					)
  
           SCREAMING_SNAKE_CASE__			:				Any       						= 1_0
           SCREAMING_SNAKE_CASE__			:				Tuple       						= self.dummy_model()
           SCREAMING_SNAKE_CASE__			:				Optional[int]       						= self.dummy_sample_deter.half()
           scheduler.set_timesteps(a__					)
  
           for i, t in enumerate(scheduler.timesteps					):
              SCREAMING_SNAKE_CASE__			:				Any       						= model(a__ ,  a__					)
              SCREAMING_SNAKE_CASE__			:				Any       						= scheduler.step(a__ ,  a__ ,  a__					).prev_sample
  
           assert sample.dtype == torch.floataa
  
  
  
  
  
  
        def    A__(self ,  **a__					)       ->   Dict:
           for scheduler_class in self.scheduler_classes:
              SCREAMING_SNAKE_CASE__			:				Optional[int]       						= self.get_scheduler_config(**a__					)
              SCREAMING_SNAKE_CASE__			:				List[str]       						= scheduler_class(**a__					)
  
              scheduler.set_timesteps(scheduler.config.num_train_timesteps					)
              assert len(scheduler.timesteps.unique()					) == scheduler.num_inference_steps
  
  
style_context: 
  
  
  
  
  '''simple docstring'''
  
  
  
  
  
  # Copyright 2023 The HuggingFace Team. All rights reserved.
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #     http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  from typing import TYPE_CHECKING
  
  # rely on isort to merge the imports
  from ...utils import (
      OptionalDependencyNotAvailable,
      _LazyModule,
      is_torch_available,
  )
  
  
  lowercase__			=	{
      '''configuration_convnextv2''': [
          '''CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP''',
          '''ConvNextV2Config''',
      ]
  }
  
  try:
         if not is_torch_available():
                raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
         pass
  else:
         lowercase__			=	[
             '''CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST''',
             '''ConvNextV2ForImageClassification''',
             '''ConvNextV2Model''',
             '''ConvNextV2PreTrainedModel''',
             '''ConvNextV2Backbone''',
         ]
  
  
  if TYPE_CHECKING:
         from .configuration_convnextva import (
             CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP,
             ConvNextVaConfig,
         )
  
         try:
                if not is_torch_available():
                       raise OptionalDependencyNotAvailable()
         except OptionalDependencyNotAvailable:
                pass
         else:
                from .modeling_convnextva import (
                    CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST,
                    ConvNextVaBackbone,
                    ConvNextVaForImageClassification,
                    ConvNextVaModel,
                    ConvNextVaPreTrainedModel,
                )
  
  else:
         import sys
  
         lowercase__			=	_LazyModule(__name__, globals()['''__file__'''], _import_structure)
  
  