





import torch

from diffusers import EulerDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest




class     SCREAMING_SNAKE_CASE__ (						__snake_case      ):
 __SCREAMING_SNAKE_CASE							       =	(EulerDiscreteScheduler,)
 __SCREAMING_SNAKE_CASE							       =	10



 def 				UpperCamelCase			(							self,**__lowerCamelCase ):
        A__											=						{
            "num_train_timesteps": 1100,
            "beta_start": 0.0001,
            "beta_end": 0.02,
            "beta_schedule": "linear",
        }

        config.update(**A_ )
        return config



 def 				UpperCamelCase			(							self ):




        for timesteps in [10, 50, 100, 1000]:
               self.check_over_configs(num_train_timesteps=A_ )



 def 				UpperCamelCase			(							self ):




        for beta_start, beta_end in zip([0.00001, 0.0001, 0.001],[0.0002, 0.002, 0.02] ):
               self.check_over_configs(beta_start=A_,beta_end=A_ )



 def 				UpperCamelCase			(							self ):




        for schedule in ["linear", "scaled_linear"]:
               self.check_over_configs(beta_schedule=A_ )



 def 				UpperCamelCase			(							self ):




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



 def 				UpperCamelCase			(							self ):
        A__											=						self.scheduler_classes[0]
        A__											=						self.get_scheduler_config()
        A__											=						scheduler_class(**A_ )

        scheduler.set_timesteps(self.num_inference_steps )

        A__											=						torch.manual_seed(0 )

        A__											=						self.dummy_model()
        A__											=						self.dummy_sample_deter * scheduler.init_noise_sigma
        A__											=						sample.to(A_ )

        for i, t in enumerate(scheduler.timesteps ):
               A__											=						scheduler.scale_model_input(A_,A_ )

               A__											=						model(A_,A_ )

               A__											=						scheduler.step(A_,A_,A_,generator=A_ )
               A__											=						output.prev_sample

        A__											=						torch.sum(torch.abs(A_ ) )
        A__											=						torch.mean(torch.abs(A_ ) )

        assert abs(result_sum.item() - 10.0807 ) < 1E-2
        assert abs(result_mean.item() - 0.0131 ) < 1E-3



 def 				UpperCamelCase			(							self ):
        A__											=						self.scheduler_classes[0]
        A__											=						self.get_scheduler_config(prediction_type='''v_prediction''' )
        A__											=						scheduler_class(**A_ )

        scheduler.set_timesteps(self.num_inference_steps )

        A__											=						torch.manual_seed(0 )

        A__											=						self.dummy_model()
        A__											=						self.dummy_sample_deter * scheduler.init_noise_sigma
        A__											=						sample.to(A_ )

        for i, t in enumerate(scheduler.timesteps ):
               A__											=						scheduler.scale_model_input(A_,A_ )

               A__											=						model(A_,A_ )

               A__											=						scheduler.step(A_,A_,A_,generator=A_ )
               A__											=						output.prev_sample

        A__											=						torch.sum(torch.abs(A_ ) )
        A__											=						torch.mean(torch.abs(A_ ) )

        assert abs(result_sum.item() - 0.0002 ) < 1E-2
        assert abs(result_mean.item() - 2.26_76E-06 ) < 1E-3



 def 				UpperCamelCase			(							self ):
        A__											=						self.scheduler_classes[0]
        A__											=						self.get_scheduler_config()
        A__											=						scheduler_class(**A_ )

        scheduler.set_timesteps(self.num_inference_steps,device=A_ )

        A__											=						torch.manual_seed(0 )

        A__											=						self.dummy_model()
        A__											=						self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
        A__											=						sample.to(A_ )

        for t in scheduler.timesteps:
               A__											=						scheduler.scale_model_input(A_,A_ )

               A__											=						model(A_,A_ )

               A__											=						scheduler.step(A_,A_,A_,generator=A_ )
               A__											=						output.prev_sample

        A__											=						torch.sum(torch.abs(A_ ) )
        A__											=						torch.mean(torch.abs(A_ ) )

        assert abs(result_sum.item() - 10.0807 ) < 1E-2
        assert abs(result_mean.item() - 0.0131 ) < 1E-3




 def 				UpperCamelCase			(							self ):
        A__											=						self.scheduler_classes[0]
        A__											=						self.get_scheduler_config()
        A__											=						scheduler_class(**A_,use_karras_sigmas=A_ )

        scheduler.set_timesteps(self.num_inference_steps,device=A_ )

        A__											=						torch.manual_seed(0 )

        A__											=						self.dummy_model()
        A__											=						self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
        A__											=						sample.to(A_ )

        for t in scheduler.timesteps:
               A__											=						scheduler.scale_model_input(A_,A_ )

               A__											=						model(A_,A_ )

               A__											=						scheduler.step(A_,A_,A_,generator=A_ )
               A__											=						output.prev_sample

        A__											=						torch.sum(torch.abs(A_ ) )
        A__											=						torch.mean(torch.abs(A_ ) )

        assert abs(result_sum.item() - 124.52_2994_9951_1719 ) < 1E-2
        assert abs(result_mean.item() - 0.16213932633399963 ) < 1E-3












import pytest
import requests

from datasets.utils.file_utils import http_head

from .utils import OfflineSimulationMode, RequestWouldHangIndefinitelyError, offline



@pytest.mark.integration
def 		A_				(     )						-> List[Any]:
 with offline(OfflineSimulationMode.CONNECTION_TIMES_OUT     ):
  with pytest.raises(_lowerCAmelCase     ):
   requests.request("GET"							,   "https://huggingface.co"     )
  with pytest.raises(requests.exceptions.ConnectTimeout     ):
   requests.request("GET"							,   "https://huggingface.co"							,   timeout=1.0     )



@pytest.mark.integration
def 		A_				(     )						-> Tuple:
 with offline(OfflineSimulationMode.CONNECTION_FAILS     ):
  with pytest.raises(requests.exceptions.ConnectionError     ):
   requests.request("GET"							,   "https://huggingface.co"     )



def 		A_				(     )						-> Optional[int]:
 with offline(OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1     ):
  with pytest.raises(_lowerCAmelCase     ):
   http_head("https://huggingface.co"     )
