code: 
  
  
  
  
  
  
  import tempfile
  
  import torch
  
  from diffusers import (
      DEISMultistepScheduler,
      DPMSolverMultistepScheduler,
      DPMSolverSinglestepScheduler,
      UniPCMultistepScheduler,
  )
  
  from .test_schedulers import SchedulerCommonTest
  
  
  
  
  
  
  
  class     UpperCAmelCase_		(      lowercase				):
  
  
  
        """simple docstring"""
        UpperCamelCase_       :      Optional[Any]     =(DPMSolverMultistepScheduler,)
        UpperCamelCase_       :      int     =(('num_inference_steps', 25),)
        def 					UpperCAmelCase		(       self					,       **SCREAMING_SNAKE_CASE_				)       ->   Optional[int]:
            UpperCamelCase :Tuple										=     {
                '''num_train_timesteps''': 1000,
                '''beta_start''': 0.0001,
                '''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(**SCREAMING_SNAKE_CASE_				)
            return config
        def 					UpperCAmelCase		(       self					,       SCREAMING_SNAKE_CASE_=0					,       **SCREAMING_SNAKE_CASE_				)       ->   str:
            UpperCamelCase :int										=     dict(self.forward_default_kwargs				)
            UpperCamelCase :Dict										=     kwargs.pop('''num_inference_steps'''					,       SCREAMING_SNAKE_CASE_				)
            UpperCamelCase :str										=     self.dummy_sample
            UpperCamelCase :Optional[Any]										=     0.1 * sample
            UpperCamelCase :Optional[int]										=     [residual + 0.2, residual + 0.15, residual + 0.10]
  
            for scheduler_class in self.scheduler_classes:
                UpperCamelCase :Any										=     self.get_scheduler_config(**SCREAMING_SNAKE_CASE_				)
                UpperCamelCase :int										=     scheduler_class(**SCREAMING_SNAKE_CASE_				)
                scheduler.set_timesteps(SCREAMING_SNAKE_CASE_				)
                # copy over dummy past residuals
                UpperCamelCase :Tuple										=     dummy_past_residuals[: scheduler.config.solver_order]
  
                with tempfile.TemporaryDirectory() as tmpdirname:
                    scheduler.save_config(SCREAMING_SNAKE_CASE_				)
                    UpperCamelCase :Union[str, Any]										=     scheduler_class.from_pretrained(SCREAMING_SNAKE_CASE_				)
                    new_scheduler.set_timesteps(SCREAMING_SNAKE_CASE_				)
                    # copy over dummy past residuals
                    UpperCamelCase :List[str]										=     dummy_past_residuals[: new_scheduler.config.solver_order]
  
                UpperCamelCase							,     UpperCamelCase :Union[str, Any]										=     sample, sample
                for t in range(SCREAMING_SNAKE_CASE_					,       time_step + scheduler.config.solver_order + 1				):
                    UpperCamelCase :List[str]										=     scheduler.step(SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       **SCREAMING_SNAKE_CASE_				).prev_sample
                    UpperCamelCase :Optional[Any]										=     new_scheduler.step(SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       **SCREAMING_SNAKE_CASE_				).prev_sample
  
                    assert torch.sum(torch.abs(output - new_output				)				) < 1e-5, "Scheduler outputs are not identical"
        def 					UpperCAmelCase		(       self				)       ->   Tuple:
            pass
        def 					UpperCAmelCase		(       self					,       SCREAMING_SNAKE_CASE_=0					,       **SCREAMING_SNAKE_CASE_				)       ->   Union[str, Any]:
            UpperCamelCase :Dict										=     dict(self.forward_default_kwargs				)
            UpperCamelCase :List[Any]										=     kwargs.pop('''num_inference_steps'''					,       SCREAMING_SNAKE_CASE_				)
            UpperCamelCase :Dict										=     self.dummy_sample
            UpperCamelCase :Dict										=     0.1 * sample
            UpperCamelCase :Optional[int]										=     [residual + 0.2, residual + 0.15, residual + 0.10]
  
            for scheduler_class in self.scheduler_classes:
                UpperCamelCase :Union[str, Any]										=     self.get_scheduler_config()
                UpperCamelCase :List[str]										=     scheduler_class(**SCREAMING_SNAKE_CASE_				)
                scheduler.set_timesteps(SCREAMING_SNAKE_CASE_				)
  
                # copy over dummy past residuals (must be after setting timesteps)
                UpperCamelCase :Any										=     dummy_past_residuals[: scheduler.config.solver_order]
  
                with tempfile.TemporaryDirectory() as tmpdirname:
                    scheduler.save_config(SCREAMING_SNAKE_CASE_				)
                    UpperCamelCase :List[Any]										=     scheduler_class.from_pretrained(SCREAMING_SNAKE_CASE_				)
                    # copy over dummy past residuals
                    new_scheduler.set_timesteps(SCREAMING_SNAKE_CASE_				)
  
                    # copy over dummy past residual (must be after setting timesteps)
                    UpperCamelCase :Union[str, Any]										=     dummy_past_residuals[: new_scheduler.config.solver_order]
  
                UpperCamelCase :Any										=     scheduler.step(SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       **SCREAMING_SNAKE_CASE_				).prev_sample
                UpperCamelCase :Union[str, Any]										=     new_scheduler.step(SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       **SCREAMING_SNAKE_CASE_				).prev_sample
  
                assert torch.sum(torch.abs(output - new_output				)				) < 1e-5, "Scheduler outputs are not identical"
        def 					UpperCAmelCase		(       self					,       SCREAMING_SNAKE_CASE_=None					,       **SCREAMING_SNAKE_CASE_				)       ->   Optional[Any]:
            if scheduler is None:
                UpperCamelCase :str										=     self.scheduler_classes[0]
                UpperCamelCase :Optional[int]										=     self.get_scheduler_config(**SCREAMING_SNAKE_CASE_				)
                UpperCamelCase :Union[str, Any]										=     scheduler_class(**SCREAMING_SNAKE_CASE_				)
  
            UpperCamelCase :Dict										=     10
            UpperCamelCase :Any										=     self.dummy_model()
            UpperCamelCase :Optional[Any]										=     self.dummy_sample_deter
            scheduler.set_timesteps(SCREAMING_SNAKE_CASE_				)
  
            for i, t in enumerate(scheduler.timesteps				):
                UpperCamelCase :Optional[Any]										=     model(SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_				)
                UpperCamelCase :Dict										=     scheduler.step(SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_				).prev_sample
  
            return sample
        def 					UpperCAmelCase		(       self				)       ->   Union[str, Any]:
            UpperCamelCase :str										=     dict(self.forward_default_kwargs				)
  
            UpperCamelCase :Optional[int]										=     kwargs.pop('''num_inference_steps'''					,       SCREAMING_SNAKE_CASE_				)
  
            for scheduler_class in self.scheduler_classes:
                UpperCamelCase :int										=     self.get_scheduler_config()
                UpperCamelCase :Any										=     scheduler_class(**SCREAMING_SNAKE_CASE_				)
  
                UpperCamelCase :Dict										=     self.dummy_sample
                UpperCamelCase :Optional[int]										=     0.1 * sample
  
                if num_inference_steps is not None and hasattr(SCREAMING_SNAKE_CASE_					,       '''set_timesteps'''				):
                    scheduler.set_timesteps(SCREAMING_SNAKE_CASE_				)
                elif num_inference_steps is not None and not hasattr(SCREAMING_SNAKE_CASE_					,       '''set_timesteps'''				):
                    UpperCamelCase :int										=     num_inference_steps
  
                # copy over dummy past residuals (must be done after set_timesteps)
                UpperCamelCase :List[str]										=     [residual + 0.2, residual + 0.15, residual + 0.10]
                UpperCamelCase :str										=     dummy_past_residuals[: scheduler.config.solver_order]
  
                UpperCamelCase :str										=     scheduler.timesteps[5]
                UpperCamelCase :Any										=     scheduler.timesteps[6]
  
                UpperCamelCase :Optional[int]										=     scheduler.step(SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       **SCREAMING_SNAKE_CASE_				).prev_sample
                UpperCamelCase :Tuple										=     scheduler.step(SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       **SCREAMING_SNAKE_CASE_				).prev_sample
  
                self.assertEqual(output_a.shape					,       sample.shape				)
                self.assertEqual(output_a.shape					,       output_a.shape				)
        def 					UpperCAmelCase		(       self				)       ->   Optional[Any]:
            for timesteps in [25, 50, 100, 999, 1000]:
                self.check_over_configs(num_train_timesteps=SCREAMING_SNAKE_CASE_				)
        def 					UpperCAmelCase		(       self				)       ->   List[str]:
            self.check_over_configs(thresholding=SCREAMING_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=SCREAMING_SNAKE_CASE_					,       prediction_type=SCREAMING_SNAKE_CASE_					,       sample_max_value=SCREAMING_SNAKE_CASE_					,       algorithm_type='''dpmsolver++'''					,       solver_order=SCREAMING_SNAKE_CASE_					,       solver_type=SCREAMING_SNAKE_CASE_					,       )
        def 					UpperCAmelCase		(       self				)       ->   Optional[int]:
            for prediction_type in ["epsilon", "v_prediction"]:
                self.check_over_configs(prediction_type=SCREAMING_SNAKE_CASE_				)
        def 					UpperCAmelCase		(       self				)       ->   Dict:
            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=SCREAMING_SNAKE_CASE_					,       solver_type=SCREAMING_SNAKE_CASE_					,       prediction_type=SCREAMING_SNAKE_CASE_					,       algorithm_type=SCREAMING_SNAKE_CASE_					,       )
                            UpperCamelCase :Optional[Any]										=     self.full_loop(
                                solver_order=SCREAMING_SNAKE_CASE_					,       solver_type=SCREAMING_SNAKE_CASE_					,       prediction_type=SCREAMING_SNAKE_CASE_					,       algorithm_type=SCREAMING_SNAKE_CASE_					,       )
                            assert not torch.isnan(SCREAMING_SNAKE_CASE_				).any(), "Samples have nan numbers"
        def 					UpperCAmelCase		(       self				)       ->   List[str]:
            self.check_over_configs(lower_order_final=SCREAMING_SNAKE_CASE_				)
            self.check_over_configs(lower_order_final=SCREAMING_SNAKE_CASE_				)
        def 					UpperCAmelCase		(       self				)       ->   Union[str, Any]:
            self.check_over_configs(lambda_min_clipped=-float('''inf'''				)				)
            self.check_over_configs(lambda_min_clipped=-5.1				)
        def 					UpperCAmelCase		(       self				)       ->   str:
            self.check_over_configs(variance_type=SCREAMING_SNAKE_CASE_				)
            self.check_over_configs(variance_type='''learned_range'''				)
        def 					UpperCAmelCase		(       self				)       ->   List[Any]:
            for num_inference_steps in [1, 2, 3, 5, 10, 50, 100, 999, 1000]:
                self.check_over_forward(num_inference_steps=SCREAMING_SNAKE_CASE_					,       time_step=0				)
        def 					UpperCAmelCase		(       self				)       ->   Optional[Any]:
            UpperCamelCase :Dict										=     self.full_loop()
            UpperCamelCase :List[str]										=     torch.mean(torch.abs(SCREAMING_SNAKE_CASE_				)				)
  
            assert abs(result_mean.item() - 0.3301				) < 1e-3
        def 					UpperCAmelCase		(       self				)       ->   str:
            UpperCamelCase :str										=     self.full_loop(thresholding=SCREAMING_SNAKE_CASE_					,       dynamic_thresholding_ratio=0.87					,       sample_max_value=0.5				)
            UpperCamelCase :Optional[Any]										=     torch.mean(torch.abs(SCREAMING_SNAKE_CASE_				)				)
  
            assert abs(result_mean.item() - 1.1364				) < 1e-3
        def 					UpperCAmelCase		(       self				)       ->   Any:
            UpperCamelCase :int										=     self.full_loop(prediction_type='''v_prediction'''				)
            UpperCamelCase :Optional[int]										=     torch.mean(torch.abs(SCREAMING_SNAKE_CASE_				)				)
  
            assert abs(result_mean.item() - 0.2251				) < 1e-3
        def 					UpperCAmelCase		(       self				)       ->   Any:
            UpperCamelCase :Tuple										=     self.full_loop(prediction_type='''v_prediction'''					,       use_karras_sigmas=SCREAMING_SNAKE_CASE_				)
            UpperCamelCase :List[str]										=     torch.mean(torch.abs(SCREAMING_SNAKE_CASE_				)				)
  
            assert abs(result_mean.item() - 0.2096				) < 1e-3
        def 					UpperCAmelCase		(       self				)       ->   int:
            # make sure that iterating over schedulers with same config names gives same results
            # for defaults
            UpperCamelCase :Optional[int]										=     DPMSolverMultistepScheduler(**self.get_scheduler_config()				)
            UpperCamelCase :Dict										=     self.full_loop(scheduler=SCREAMING_SNAKE_CASE_				)
            UpperCamelCase :Optional[Any]										=     torch.mean(torch.abs(SCREAMING_SNAKE_CASE_				)				)
  
            assert abs(result_mean.item() - 0.3301				) < 1e-3
  
            UpperCamelCase :str										=     DPMSolverSinglestepScheduler.from_config(scheduler.config				)
            UpperCamelCase :Optional[int]										=     UniPCMultistepScheduler.from_config(scheduler.config				)
            UpperCamelCase :Any										=     DEISMultistepScheduler.from_config(scheduler.config				)
            UpperCamelCase :int										=     DPMSolverMultistepScheduler.from_config(scheduler.config				)
  
            UpperCamelCase :Tuple										=     self.full_loop(scheduler=SCREAMING_SNAKE_CASE_				)
            UpperCamelCase :Optional[int]										=     torch.mean(torch.abs(SCREAMING_SNAKE_CASE_				)				)
  
            assert abs(result_mean.item() - 0.3301				) < 1e-3
        def 					UpperCAmelCase		(       self				)       ->   List[Any]:
            UpperCamelCase :Dict										=     self.scheduler_classes[0]
            UpperCamelCase :str										=     self.get_scheduler_config(thresholding=SCREAMING_SNAKE_CASE_					,       dynamic_thresholding_ratio=0				)
            UpperCamelCase :str										=     scheduler_class(**SCREAMING_SNAKE_CASE_				)
  
            UpperCamelCase :Optional[int]										=     10
            UpperCamelCase :Optional[int]										=     self.dummy_model()
            UpperCamelCase :List[str]										=     self.dummy_sample_deter.half()
            scheduler.set_timesteps(SCREAMING_SNAKE_CASE_				)
  
            for i, t in enumerate(scheduler.timesteps				):
                UpperCamelCase :int										=     model(SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_				)
                UpperCamelCase :Union[str, Any]										=     scheduler.step(SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_				).prev_sample
  
            assert sample.dtype == torch.floataa
  
  
  
  
        def 					UpperCAmelCase		(       self					,       **SCREAMING_SNAKE_CASE_				)       ->   List[str]:
            for scheduler_class in self.scheduler_classes:
                UpperCamelCase :Any										=     self.get_scheduler_config(**SCREAMING_SNAKE_CASE_				)
                UpperCamelCase :int										=     scheduler_class(**SCREAMING_SNAKE_CASE_				)
  
                scheduler.set_timesteps(scheduler.config.num_train_timesteps				)
                assert len(scheduler.timesteps.unique()				) == scheduler.num_inference_steps
  
  
  
  
  
  
style_context: 
  
  
  
  
  
  
  from typing import TYPE_CHECKING
  
  from ...utils import (
      OptionalDependencyNotAvailable,
      _LazyModule,
      is_sentencepiece_available,
      is_tokenizers_available,
      is_torch_available,
  )
  
  
  __snake_case							      =						{
      """configuration_open_llama""": ["""OPEN_LLAMA_PRETRAINED_CONFIG_ARCHIVE_MAP""", """OpenLlamaConfig"""],
  }
  
  try:
   if not is_sentencepiece_available():
    raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
   pass
  else:
   __snake_case							      =						["""LlamaTokenizer"""]
  
  try:
   if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
   pass
  else:
   __snake_case							      =						["""LlamaTokenizerFast"""]
  
  try:
   if not is_torch_available():
    raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
   pass
  else:
   __snake_case							      =						[
       """OpenLlamaForCausalLM""",
       """OpenLlamaModel""",
       """OpenLlamaPreTrainedModel""",
       """OpenLlamaForSequenceClassification""",
   ]
  
  
  if TYPE_CHECKING:
   from .configuration_open_llama import OPEN_LLAMA_PRETRAINED_CONFIG_ARCHIVE_MAP, OpenLlamaConfig
  
   try:
    if not is_sentencepiece_available():
     raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
    pass
   else:
    from transformers import LlamaTokenizer
  
   try:
    if not is_tokenizers_available():
     raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
    pass
   else:
    from transformers import LlamaTokenizerFast
  
   try:
    if not is_torch_available():
     raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
    pass
   else:
    from .modeling_open_llama import (
        OpenLlamaForCausalLM,
        OpenLlamaForSequenceClassification,
        OpenLlamaModel,
        OpenLlamaPreTrainedModel,
    )
  
  
  else:
   import sys
  
   __snake_case							      =						_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)
  
  
  
  
  
  