

import torch

from diffusers import DPMSolverSDEScheduler
from diffusers.utils import torch_device
from diffusers.utils.testing_utils import require_torchsde

from .test_schedulers import SchedulerCommonTest



@require_torchsde
class       __snake_case  (    __A       ):
  __lowerCAmelCase     :	Dict						 =  (DPMSolverSDEScheduler,)
  __lowerCAmelCase     :	Optional[int]						 =  10

  def 						lowerCAmelCase__     (					self						,		**_A):
      SCREAMING_SNAKE_CASE_									=						{
          'num_train_timesteps': 1100,
          'beta_start': 0.0_0_0_1,
          'beta_end': 0.0_2,
          'beta_schedule': 'linear',
          'noise_sampler_seed': 0,
      }

      config.update(**UpperCamelCase__)
      return config

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

  def 						lowerCAmelCase__     (					self):
      for beta_start, beta_end in zip([0.0_0_0_0_1, 0.0_0_0_1, 0.0_0_1]						,		[0.0_0_0_2, 0.0_0_2, 0.0_2]):
          self.check_over_configs(beta_start=UpperCamelCase__						,		beta_end=UpperCamelCase__)

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

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

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						self.scheduler_classes[0]
      SCREAMING_SNAKE_CASE_									=						self.get_scheduler_config()
      SCREAMING_SNAKE_CASE_									=						scheduler_class(**UpperCamelCase__)

      scheduler.set_timesteps(self.num_inference_steps)

      SCREAMING_SNAKE_CASE_									=						self.dummy_model()
      SCREAMING_SNAKE_CASE_									=						self.dummy_sample_deter * scheduler.init_noise_sigma
      SCREAMING_SNAKE_CASE_									=						sample.to(UpperCamelCase__)

      for i, t in enumerate(scheduler.timesteps):
          SCREAMING_SNAKE_CASE_									=						scheduler.scale_model_input(UpperCamelCase__						,		UpperCamelCase__)

          SCREAMING_SNAKE_CASE_									=						model(UpperCamelCase__						,		UpperCamelCase__)

          SCREAMING_SNAKE_CASE_									=						scheduler.step(UpperCamelCase__						,		UpperCamelCase__						,		UpperCamelCase__)
          SCREAMING_SNAKE_CASE_									=						output.prev_sample

      SCREAMING_SNAKE_CASE_									=						torch.sum(torch.abs(UpperCamelCase__))
      SCREAMING_SNAKE_CASE_									=						torch.mean(torch.abs(UpperCamelCase__))

      if torch_device in ["mps"]:
          assert abs(result_sum.item() - 167.47821044921875) < 1E-2
          assert abs(result_mean.item() - 0.2_1_7_8_7_0_5_9_6_4_5_6_5_2_7_7) < 1E-3
      elif torch_device in ["cuda"]:
          assert abs(result_sum.item() - 171.59352111816406) < 1E-2
          assert abs(result_mean.item() - 0.2_2_3_4_2_9_0_6_8_9_2_2_9_9_6_5_2) < 1E-3
      else:
          assert abs(result_sum.item() - 162.52383422851562) < 1E-2
          assert abs(result_mean.item() - 0.2_1_1_6_1_9_5_7_0_8_5_1_3_2_6) < 1E-3

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						self.scheduler_classes[0]
      SCREAMING_SNAKE_CASE_									=						self.get_scheduler_config(prediction_type='v_prediction')
      SCREAMING_SNAKE_CASE_									=						scheduler_class(**UpperCamelCase__)

      scheduler.set_timesteps(self.num_inference_steps)

      SCREAMING_SNAKE_CASE_									=						self.dummy_model()
      SCREAMING_SNAKE_CASE_									=						self.dummy_sample_deter * scheduler.init_noise_sigma
      SCREAMING_SNAKE_CASE_									=						sample.to(UpperCamelCase__)

      for i, t in enumerate(scheduler.timesteps):
          SCREAMING_SNAKE_CASE_									=						scheduler.scale_model_input(UpperCamelCase__						,		UpperCamelCase__)

          SCREAMING_SNAKE_CASE_									=						model(UpperCamelCase__						,		UpperCamelCase__)

          SCREAMING_SNAKE_CASE_									=						scheduler.step(UpperCamelCase__						,		UpperCamelCase__						,		UpperCamelCase__)
          SCREAMING_SNAKE_CASE_									=						output.prev_sample

      SCREAMING_SNAKE_CASE_									=						torch.sum(torch.abs(UpperCamelCase__))
      SCREAMING_SNAKE_CASE_									=						torch.mean(torch.abs(UpperCamelCase__))

      if torch_device in ["mps"]:
          assert abs(result_sum.item() - 124.77149200439453) < 1E-2
          assert abs(result_mean.item() - 0.1_6_2_2_6_2_8_9_0_1_4_8_1_6_2_8_4) < 1E-3
      elif torch_device in ["cuda"]:
          assert abs(result_sum.item() - 128.1663360595703) < 1E-2
          assert abs(result_mean.item() - 0.1_6_6_8_8_3_2_6_0_0_1_1_6_7_2_9_7) < 1E-3
      else:
          assert abs(result_sum.item() - 119.8487548828125) < 1E-2
          assert abs(result_mean.item() - 0.1_5_6_0_5_3_0_6_6_2_5_3_6_6_2_1) < 1E-3

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						self.scheduler_classes[0]
      SCREAMING_SNAKE_CASE_									=						self.get_scheduler_config()
      SCREAMING_SNAKE_CASE_									=						scheduler_class(**UpperCamelCase__)

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

      SCREAMING_SNAKE_CASE_									=						self.dummy_model()
      SCREAMING_SNAKE_CASE_									=						self.dummy_sample_deter.to(UpperCamelCase__) * scheduler.init_noise_sigma

      for t in scheduler.timesteps:
          SCREAMING_SNAKE_CASE_									=						scheduler.scale_model_input(UpperCamelCase__						,		UpperCamelCase__)

          SCREAMING_SNAKE_CASE_									=						model(UpperCamelCase__						,		UpperCamelCase__)

          SCREAMING_SNAKE_CASE_									=						scheduler.step(UpperCamelCase__						,		UpperCamelCase__						,		UpperCamelCase__)
          SCREAMING_SNAKE_CASE_									=						output.prev_sample

      SCREAMING_SNAKE_CASE_									=						torch.sum(torch.abs(UpperCamelCase__))
      SCREAMING_SNAKE_CASE_									=						torch.mean(torch.abs(UpperCamelCase__))

      if torch_device in ["mps"]:
          assert abs(result_sum.item() - 167.46957397460938) < 1E-2
          assert abs(result_mean.item() - 0.2_1_8_0_5_9_3_4_6_0_7_9_8_2_6_3_5) < 1E-3
      elif torch_device in ["cuda"]:
          assert abs(result_sum.item() - 171.59353637695312) < 1E-2
          assert abs(result_mean.item() - 0.2_2_3_4_2_9_0_8_3_8_2_4_1_5_7_7_1) < 1E-3
      else:
          assert abs(result_sum.item() - 162.52383422851562) < 1E-2
          assert abs(result_mean.item() - 0.2_1_1_6_1_9_5_7_0_8_5_1_3_2_6) < 1E-3


  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						self.scheduler_classes[0]
      SCREAMING_SNAKE_CASE_									=						self.get_scheduler_config()
      SCREAMING_SNAKE_CASE_									=						scheduler_class(**UpperCamelCase__						,		use_karras_sigmas=UpperCamelCase__)

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

      SCREAMING_SNAKE_CASE_									=						self.dummy_model()
      SCREAMING_SNAKE_CASE_									=						self.dummy_sample_deter.to(UpperCamelCase__) * scheduler.init_noise_sigma
      SCREAMING_SNAKE_CASE_									=						sample.to(UpperCamelCase__)

      for t in scheduler.timesteps:
          SCREAMING_SNAKE_CASE_									=						scheduler.scale_model_input(UpperCamelCase__						,		UpperCamelCase__)

          SCREAMING_SNAKE_CASE_									=						model(UpperCamelCase__						,		UpperCamelCase__)

          SCREAMING_SNAKE_CASE_									=						scheduler.step(UpperCamelCase__						,		UpperCamelCase__						,		UpperCamelCase__)
          SCREAMING_SNAKE_CASE_									=						output.prev_sample

      SCREAMING_SNAKE_CASE_									=						torch.sum(torch.abs(UpperCamelCase__))
      SCREAMING_SNAKE_CASE_									=						torch.mean(torch.abs(UpperCamelCase__))

      if torch_device in ["mps"]:
          assert abs(result_sum.item() - 176.66974135742188) < 1E-2
          assert abs(result_mean.item() - 0.2_3_0_0_3_8_7_2_7_3_0_9_8_1_8_1_1) < 1E-2
      elif torch_device in ["cuda"]:
          assert abs(result_sum.item() - 177.63653564453125) < 1E-2
          assert abs(result_mean.item() - 0.2_3_0_0_3_8_7_2_7_3_0_9_8_1_8_1_1) < 1E-2
      else:
          assert abs(result_sum.item() - 170.3135223388672) < 1E-2
          assert abs(result_mean.item() - 0.2_3_0_0_3_8_7_2_7_3_0_9_8_1_8_1_1) < 1E-2






import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


UpperCamelCase__  :      int			=    "\nHugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.\n\nIn March 2021, Hugging Face raised $40 million in a Series B funding round.[3]\n\nOn April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]\n"



class       __snake_case  (    unittest.TestCase     , lowerCAmelCase__       ):

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						load_tool('text-question-answering')
      self.tool.setup()
      SCREAMING_SNAKE_CASE_									=						load_tool('text-question-answering'						,		remote=_A)

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						self.tool(_A						,		'What did Hugging Face do in April 2021?')
      self.assertEqual(_A						,		'launched the BigScience Research Workshop')

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						self.remote_tool(_A						,		'What did Hugging Face do in April 2021?')
      self.assertEqual(_A						,		'launched the BigScience Research Workshop')

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						self.tool(text=_A						,		question='What did Hugging Face do in April 2021?')
      self.assertEqual(_A						,		'launched the BigScience Research Workshop')


  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						self.remote_tool(text=_A						,		question='What did Hugging Face do in April 2021?')
      self.assertEqual(_A						,		'launched the BigScience Research Workshop')


