




"""simple docstring"""






import tempfile
import unittest

from transformers import TaConfig, is_torch_available
from transformers.testing_utils import (
    require_sentencepiece,
    require_tokenizers,
    require_torch,
    slow,
    torch_device,
)

from ...generation.test_utils import GenerationTesterMixin
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers import AutoTokenizer, UMTaForConditionalGeneration, UMTaForQuestionAnswering, UMTaModel




class   a__			:





						def __init__(							self      :	str     ,a__      :	List[str]     ,a__      :	List[str]=99     ,a__      :	Optional[Any]=13     ,a__      :	Tuple=7     ,a__      :	str=9     ,a__      :	List[str]=True     ,a__      :	List[Any]=True     ,a__      :	int=False     ,a__      :	Optional[Any]=32     ,a__      :	Any=5     ,a__      :	Tuple=4     ,a__      :	List[str]=37     ,a__      :	Optional[Any]=8     ,a__      :	Union[str, Any]=0.1     ,a__      :	Optional[Any]=0.002     ,a__      :	int=1     ,a__      :	Union[str, Any]=0     ,a__      :	List[str]=0     ,a__      :	Optional[int]=None     ,a__      :	Optional[int]=None     ,)						->       str:




											"""simple docstring"""







											_lowerCAmelCase:Any									=  parent
											_lowerCAmelCase:List[str]									=  batch_size
											_lowerCAmelCase:List[str]									=  encoder_seq_length
											_lowerCAmelCase:Tuple									=  decoder_seq_length
											# For common tests
											_lowerCAmelCase:str									=  self.decoder_seq_length
											_lowerCAmelCase:Any									=  is_training
											_lowerCAmelCase:List[str]									=  use_attention_mask
											_lowerCAmelCase:int									=  use_labels
											_lowerCAmelCase:Union[str, Any]									=  vocab_size
											_lowerCAmelCase:Tuple									=  hidden_size
											_lowerCAmelCase:List[Any]									=  num_hidden_layers
											_lowerCAmelCase:Union[str, Any]									=  num_attention_heads
											_lowerCAmelCase:List[str]									=  d_ff
											_lowerCAmelCase:Union[str, Any]									=  relative_attention_num_buckets
											_lowerCAmelCase:List[str]									=  dropout_rate
											_lowerCAmelCase:int									=  initializer_factor
											_lowerCAmelCase:Dict									=  eos_token_id
											_lowerCAmelCase:Dict									=  pad_token_id
											_lowerCAmelCase:List[Any]									=  decoder_start_token_id
											_lowerCAmelCase:Any									=  None
											_lowerCAmelCase:Dict									=  decoder_layers





						def       __UpperCamelCase     (							self      :	Any)						->       Any:




											"""simple docstring"""







											return TaConfig.from_pretrained('''google/umt5-base''')





						def       __UpperCamelCase     (							self      :	Dict     ,a__      :	Union[str, Any]     ,a__      :	Any     ,a__      :	int     ,a__      :	List[str]=None     ,a__      :	Optional[int]=None     ,a__      :	Dict=None     ,a__      :	int=None     ,a__      :	Dict=None     ,)						->       Optional[int]:




											"""simple docstring"""







											if attention_mask is None:
																_lowerCAmelCase:str									=  input_ids.ne(config.pad_token_id)
											if decoder_attention_mask is None:
																_lowerCAmelCase:str									=  decoder_input_ids.ne(config.pad_token_id)
											if head_mask is None:
																_lowerCAmelCase:Tuple									=  torch.ones(config.num_hidden_layers     ,config.num_attention_heads     ,device=lowercase_)
											if decoder_head_mask is None:
																_lowerCAmelCase:str									=  torch.ones(config.num_decoder_layers     ,config.num_attention_heads     ,device=lowercase_)
											if cross_attn_head_mask is None:
																_lowerCAmelCase:int									=  torch.ones(
																    config.num_decoder_layers     ,config.num_attention_heads     ,device=lowercase_)
											return {
											    "input_ids": input_ids,
											    "decoder_input_ids": decoder_input_ids,
											    "attention_mask": attention_mask,
											    "decoder_attention_mask": decoder_attention_mask,
											    "head_mask": head_mask,
											    "decoder_head_mask": decoder_head_mask,
											    "cross_attn_head_mask": cross_attn_head_mask,
											}





						def       __UpperCamelCase     (							self      :	str)						->       List[str]:




											"""simple docstring"""







											_lowerCAmelCase:List[str]									=  ids_tensor([self.batch_size, self.encoder_seq_length]     ,self.vocab_size)
											_lowerCAmelCase:Optional[Any]									=  ids_tensor([self.batch_size, self.decoder_seq_length]     ,self.vocab_size)

											# we need to clamp the input ids here to avoid having pad token in between
											# this is because for NllbMoe the position_ids are prepared such that
											# all pad tokens have pos id = 2 and rest are between 2..seq_length
											# and the seq_length here is seq_length - num_pad_tokens
											# but when using past, there is no way of knowing if the past input ids had
											# pad tokens in them, which results in incorrect seq_lenth and which in turn results in
											# position_ids being off by num_pad_tokens in past input
											_lowerCAmelCase:Dict									=  input_ids.clamp(self.pad_token_id + 1)
											_lowerCAmelCase:Dict									=  decoder_input_ids.clamp(self.pad_token_id + 1)

											_lowerCAmelCase:Tuple									=  self.get_config()
											_lowerCAmelCase:Optional[int]									=  config.num_attention_heads
											_lowerCAmelCase:List[str]									=  self.prepare_inputs_dict(lowercase_     ,lowercase_     ,lowercase_)
											return config, input_dict





						def       __UpperCamelCase     (							self      :	Optional[Any])						->       List[Any]:




											"""simple docstring"""







											_lowerCAmelCase:Dict									=  self.prepare_config_and_inputs()
											return config, inputs_dict





						def       __UpperCamelCase     (							self      :	str)						->       Tuple:




											"""simple docstring"""







											return TaConfig(
											    vocab_size=166     ,d_model=self.hidden_size     ,d_ff=self.d_ff     ,d_kv=self.hidden_size // self.num_attention_heads     ,num_layers=self.num_hidden_layers     ,num_decoder_layers=self.decoder_layers     ,num_heads=self.num_attention_heads     ,relative_attention_num_buckets=self.relative_attention_num_buckets     ,dropout_rate=self.dropout_rate     ,initializer_factor=self.initializer_factor     ,eos_token_id=self.eos_token_id     ,bos_token_id=self.pad_token_id     ,pad_token_id=self.pad_token_id     ,decoder_start_token_id=self.decoder_start_token_id     ,)





						def       __UpperCamelCase     (							self      :	str)						->       List[Any]:




											"""simple docstring"""







											return TaConfig(
											    vocab_size=self.vocab_size     ,d_model=self.hidden_size     ,d_ff=self.d_ff     ,d_kv=self.hidden_size // self.num_attention_heads     ,num_layers=self.num_hidden_layers     ,num_decoder_layers=self.decoder_layers     ,num_heads=self.num_attention_heads     ,relative_attention_num_buckets=self.relative_attention_num_buckets     ,dropout_rate=self.dropout_rate     ,initializer_factor=self.initializer_factor     ,eos_token_id=self.eos_token_id     ,bos_token_id=self.pad_token_id     ,pad_token_id=self.pad_token_id     ,decoder_start_token_id=self.decoder_start_token_id     ,)





						def       __UpperCamelCase     (							self      :	Optional[int]     ,a__      :	Any     ,a__      :	List[str]     ,a__      :	Any     ,a__      :	List[Any]     ,a__      :	List[Any]     ,a__      :	Optional[int]     ,)						->       Any:




											"""simple docstring"""







											_lowerCAmelCase:Union[str, Any]									=  UMTaModel(config=lowercase_)
											model.to(lowercase_)
											model.eval()
											_lowerCAmelCase:List[str]									=  model(
											    input_ids=lowercase_     ,decoder_input_ids=lowercase_     ,attention_mask=lowercase_     ,decoder_attention_mask=lowercase_     ,)
											_lowerCAmelCase:str									=  model(input_ids=lowercase_     ,decoder_input_ids=lowercase_)
											_lowerCAmelCase:List[Any]									=  result.last_hidden_state
											_lowerCAmelCase:Tuple									=  result.past_key_values
											_lowerCAmelCase:str									=  result.encoder_last_hidden_state

											self.parent.assertEqual(encoder_output.size()     ,(self.batch_size, self.encoder_seq_length, self.hidden_size))
											self.parent.assertEqual(decoder_output.size()     ,(self.batch_size, self.decoder_seq_length, self.hidden_size))
											# There should be `num_layers` key value embeddings stored in decoder_past
											self.parent.assertEqual(len(lowercase_)     ,config.num_layers)
											# There should be a self attn key, a self attn value, a cross attn key and a cross attn value stored in each decoder_past tuple
											self.parent.assertEqual(len(decoder_past[0])     ,4)





						def       __UpperCamelCase     (							self      :	Union[str, Any]     ,a__      :	Union[str, Any]     ,a__      :	List[str]     ,a__      :	Tuple     ,a__      :	int     ,a__      :	Any     ,a__      :	Union[str, Any]     ,)						->       Optional[int]:




											"""simple docstring"""







											_lowerCAmelCase:List[Any]									=  UMTaModel(config=lowercase_).get_decoder().to(lowercase_).eval()
											# first forward pass
											_lowerCAmelCase:List[str]									=  model(lowercase_     ,use_cache=lowercase_)
											_lowerCAmelCase:List[str]									=  model(lowercase_)
											_lowerCAmelCase:Optional[Any]									=  model(lowercase_     ,use_cache=lowercase_)

											self.parent.assertTrue(len(lowercase_) == len(lowercase_))
											self.parent.assertTrue(len(lowercase_) == len(lowercase_) + 1)

											_lowerCAmelCase:Any									=  outputs.to_tuple()

											# create hypothetical next token and extent to next_input_ids
											_lowerCAmelCase:Optional[Any]									=  ids_tensor((self.batch_size, 1)     ,config.vocab_size)

											# append to next input_ids and
											_lowerCAmelCase:List[str]									=  torch.cat([input_ids, next_tokens]     ,dim=-1)

											_lowerCAmelCase:Optional[int]									=  model(lowercase_)["last_hidden_state"]
											_lowerCAmelCase:Any									=  model(lowercase_     ,past_key_values=lowercase_)["last_hidden_state"]

											# select random slice
											_lowerCAmelCase:List[Any]									=  ids_tensor((1,)     ,output_from_past.shape[-1]).item()
											_lowerCAmelCase:str									=  output_from_no_past[:, -1, random_slice_idx].detach()
											_lowerCAmelCase:Optional[Any]									=  output_from_past[:, 0, random_slice_idx].detach()

											# test that outputs are equal for slice
											self.parent.assertTrue(torch.allclose(lowercase_     ,lowercase_     ,atol=1E-3))







						def       __UpperCamelCase     (							self      :	Union[str, Any]     ,a__      :	Dict     ,a__      :	Tuple     ,)						->       List[Any]:




											"""simple docstring"""







											_lowerCAmelCase:int									=  UMTaModel(config=lowercase_).to(lowercase_).half().eval()
											_lowerCAmelCase:Tuple									=  model(**lowercase_)["last_hidden_state"]
											self.parent.assertFalse(torch.isnan(lowercase_).any().item())




@require_torch
class   a__			(       snake_case__					,	snake_case__					,	snake_case__					,	unittest.TestCase  ):
						snake_case__             = (
						    (UMTaModel, UMTaForConditionalGeneration, UMTaForQuestionAnswering) if is_torch_available() else ()
						)
						snake_case__             = (UMTaForConditionalGeneration,) if is_torch_available() else ()
						snake_case__             = (
						    {
						        '''conversational''': UMTaForConditionalGeneration,
						        '''feature-extraction''': UMTaModel,
						        '''summarization''': UMTaForConditionalGeneration,
						        '''text2text-generation''': UMTaForConditionalGeneration,
						        '''translation''': UMTaForConditionalGeneration,
						        '''question-answering''': UMTaForQuestionAnswering,
						    }
						    if is_torch_available()
						    else {}
						)
						snake_case__             = True
						snake_case__             = False
						snake_case__             = False
						snake_case__             = True
						snake_case__             = True
						# The small UMT5 model needs higher percentages for CPU/MP tests
						snake_case__             = [0.8, 0.9]





						def       __UpperCamelCase     (							self      :	List[Any])						->       str:




											"""simple docstring"""







											_lowerCAmelCase:Optional[Any]									=  UMTaModelTester(self)





						@unittest.skip('''Test has a segmentation fault on torch 1.8.0''')
						def       __UpperCamelCase     (							self      :	int)						->       Union[str, Any]:




											"""simple docstring"""







											_lowerCAmelCase:List[Any]									=  self.model_tester.prepare_config_and_inputs()
											_lowerCAmelCase:List[str]									=  UMTaModel(config_and_inputs[0]).to(lowercase_)
											with tempfile.TemporaryDirectory() as tmpdirname:
																torch.onnx.export(
																    lowercase_     ,(config_and_inputs[1], config_and_inputs[3], config_and_inputs[2])     ,F'{tmpdirname}/t5_test.onnx'     ,export_params=lowercase_     ,opset_version=9     ,input_names=['''input_ids''', '''decoder_input_ids''']     ,)





						@unittest.skipIf(torch_device == '''cpu'''     ,'''Cant do half precision''')
						def       __UpperCamelCase     (							self      :	Tuple)						->       Optional[int]:




											"""simple docstring"""







											_lowerCAmelCase:Optional[int]									=  self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model_fpaa_forward(*lowercase_)





						def       __UpperCamelCase     (							self      :	int)						->       List[Any]:




											"""simple docstring"""







											_lowerCAmelCase:Tuple									=  ["encoder_attentions", "decoder_attentions", "cross_attentions"]
											_lowerCAmelCase:List[Any]									=  self.model_tester.prepare_config_and_inputs()
											_lowerCAmelCase:Union[str, Any]									=  config_and_inputs[0]
											_lowerCAmelCase:Optional[int]									=  UMTaForConditionalGeneration(lowercase_).eval()
											model.to(lowercase_)

											_lowerCAmelCase:List[str]									=  {
											    "head_mask": torch.zeros(config.num_layers     ,config.num_heads     ,device=lowercase_),
											    "decoder_head_mask": torch.zeros(config.num_decoder_layers     ,config.num_heads     ,device=lowercase_),
											    "cross_attn_head_mask": torch.zeros(config.num_decoder_layers     ,config.num_heads     ,device=lowercase_),
											}

											for attn_name, (name, mask) in zip(lowercase_     ,head_masking.items()):
																_lowerCAmelCase:List[str]									=  {name: mask}
																# Explicitly pass decoder_head_mask as it is required from T5 model when head_mask specified
																if name == "head_mask":
																					_lowerCAmelCase:List[Any]									=  torch.ones(
																					    config.num_decoder_layers     ,config.num_heads     ,device=lowercase_)

																_lowerCAmelCase:Tuple									=  model.generate(
																    config_and_inputs[1]['''input_ids''']     ,num_beams=1     ,max_length=3     ,output_attentions=lowercase_     ,return_dict_in_generate=lowercase_     ,**lowercase_     ,)
																# We check the state of decoder_attentions and cross_attentions just from the last step
																_lowerCAmelCase:Union[str, Any]									=  out[attn_name] if attn_name == attention_names[0] else out[attn_name][-1]
																self.assertEqual(sum([w.sum().item() for w in attn_weights])     ,0.0)







						@unittest.skip('''Does not work on the tiny model as we keep hitting edge cases.''')
						def       __UpperCamelCase     (							self      :	Tuple)						->       Optional[int]:




											"""simple docstring"""







											pass




@require_torch
@require_sentencepiece
@require_tokenizers
class   a__			(       unittest.TestCase  ):





						@slow
						@unittest.skip(
						    '''Unless we stop stripping left and right by default for all special tokens, the expected ids obtained here will not match the original ones. Wait for https://github.com/huggingface/transformers/pull/23909 to be merged''')
						def       __UpperCamelCase     (							self      :	str)						->       Union[str, Any]:




											"""simple docstring"""







											_lowerCAmelCase:Dict									=  UMTaForConditionalGeneration.from_pretrained('''google/umt5-small'''     ,return_dict=lowercase_).to(lowercase_)
											_lowerCAmelCase:Optional[int]									=  AutoTokenizer.from_pretrained('''google/umt5-small'''     ,use_fast=lowercase_     ,legacy=lowercase_)
											_lowerCAmelCase:Union[str, Any]									=  [
											    "Bonjour monsieur <extra_id_0> bien <extra_id_1>.",
											    "No se como puedo <extra_id_0>.",
											    "This is the reason why we <extra_id_0> them.",
											    "The <extra_id_0> walks in <extra_id_1>, seats",
											    "A <extra_id_0> walks into a bar and orders a <extra_id_1> with <extra_id_2> pinch of <extra_id_3>.",
											]
											_lowerCAmelCase:List[Any]									=  tokenizer(lowercase_     ,return_tensors='''pt'''     ,padding=lowercase_).input_ids
											# fmt: off
											_lowerCAmelCase:Union[str, Any]									=  torch.tensor(
											    [
											        [ 3_8530, 21_0703, 25_6299, 1410, 25_6298, 274, 1, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0],
											        [   826, 321, 671, 2_5922, 25_6299, 274, 1, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0],
											        [  1460, 339, 312, 1_9014, 1_0620, 758, 25_6299, 2355,274, 1, 0, 0, 0, 0, 0, 0,0, 0],
											        [   517, 25_6299, 1_4869, 281, 301, 25_6298, 275, 11_9983,1, 0, 0, 0, 0, 0, 0, 0,0, 0],
											        [   320, 25_6299, 1_4869, 281, 2234, 289, 2275, 333,6_1391, 289, 25_6298, 543, 25_6297, 16_8714, 329, 25_6296,274, 1],
											    ])
											# fmt: on
											torch.testing.assert_allclose(lowercase_     ,lowercase_)

											_lowerCAmelCase:List[Any]									=  model.generate(input_ids.to(lowercase_))
											_lowerCAmelCase:Dict									=  [
											    "<pad><extra_id_0> et<extra_id_1> [eod] <extra_id_2><extra_id_55>.. [eod] 💐 💐 💐 💐 💐 💐 💐 💐 💐 💐 💐 <extra_id_56>ajšietosto<extra_id_56>lleux<extra_id_19><extra_id_6>ajšie</s>",
											    "<pad><extra_id_0>.<extra_id_1>.,<0x0A>...spech <0x0A><extra_id_20> <extra_id_21></s><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad>",
											    "<pad><extra_id_0> are not going to be a part of the world. We are not going to be a part of<extra_id_1> and<extra_id_2><0x0A><extra_id_48>.<extra_id_48></s><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad>",
											    "<pad><extra_id_0> door<extra_id_1>, the door<extra_id_2> 피해[/</s><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad>",
											    "<pad><extra_id_0>nyone who<extra_id_1> drink<extra_id_2> a<extra_id_3> alcohol<extra_id_4> A<extra_id_5> A. This<extra_id_6> I<extra_id_7><extra_id_52><extra_id_53></s><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad>",
											]
											_lowerCAmelCase:Optional[Any]									=  tokenizer.batch_decode(lowercase_)
											self.assertEqual(lowercase_     ,lowercase_)












"""simple docstring"""






import torch

from diffusers import KDPMaDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest




class   a__			(       UpperCamelCase_  ):
						snake_case__             = (KDPMaDiscreteScheduler,)
						snake_case__             = 1_0





						def       __UpperCamelCase     (							self      :	Dict     ,**a__      :	str)						->       int:




											"""simple docstring"""







											_lowerCAmelCase:Optional[int]									=  {
											    '''num_train_timesteps''': 1100,
											    '''beta_start''': 0.0001,
											    '''beta_end''': 0.02,
											    '''beta_schedule''': '''linear''',
											}

											config.update(**a__)
											return config





						def       __UpperCamelCase     (							self      :	Optional[int])						->       Optional[int]:




											"""simple docstring"""







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





						def       __UpperCamelCase     (							self      :	Union[str, Any])						->       Optional[int]:




											"""simple docstring"""







											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      :	Optional[Any])						->       Union[str, Any]:




											"""simple docstring"""







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





						def       __UpperCamelCase     (							self      :	str)						->       str:




											"""simple docstring"""







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





						def       __UpperCamelCase     (							self      :	Tuple)						->       Tuple:




											"""simple docstring"""







											_lowerCAmelCase:Union[str, Any]									=  self.scheduler_classes[0]
											_lowerCAmelCase:Union[str, Any]									=  self.get_scheduler_config(prediction_type='''v_prediction''')
											_lowerCAmelCase:Tuple									=  scheduler_class(**a__)

											scheduler.set_timesteps(self.num_inference_steps)

											_lowerCAmelCase:Optional[Any]									=  self.dummy_model()
											_lowerCAmelCase:List[Any]									=  self.dummy_sample_deter * scheduler.init_noise_sigma
											_lowerCAmelCase:Optional[Any]									=  sample.to(a__)

											for i, t in enumerate(scheduler.timesteps):
																_lowerCAmelCase:Tuple									=  scheduler.scale_model_input(a__     ,a__)

																_lowerCAmelCase:Any									=  model(a__     ,a__)

																_lowerCAmelCase:Union[str, Any]									=  scheduler.step(a__     ,a__     ,a__)
																_lowerCAmelCase:Optional[int]									=  output.prev_sample

											_lowerCAmelCase:str									=  torch.sum(torch.abs(a__))
											_lowerCAmelCase:Union[str, Any]									=  torch.mean(torch.abs(a__))

											if torch_device in ["cpu", "mps"]:
																assert abs(result_sum.item() - 4.6_934E-07) < 1E-2
																assert abs(result_mean.item() - 6.1_112E-10) < 1E-3
											else:
																# CUDA
																assert abs(result_sum.item() - 4.693_428_650_170_972E-07) < 1E-2
																assert abs(result_mean.item() - 0.0002) < 1E-3





						def       __UpperCamelCase     (							self      :	Tuple)						->       Dict:




											"""simple docstring"""







											if torch_device == "mps":
																return
											_lowerCAmelCase:Tuple									=  self.scheduler_classes[0]
											_lowerCAmelCase:List[str]									=  self.get_scheduler_config()
											_lowerCAmelCase:Union[str, Any]									=  scheduler_class(**a__)

											scheduler.set_timesteps(self.num_inference_steps)

											_lowerCAmelCase:Any									=  self.dummy_model()
											_lowerCAmelCase:str									=  self.dummy_sample_deter * scheduler.init_noise_sigma
											_lowerCAmelCase:List[str]									=  sample.to(a__)

											for i, t in enumerate(scheduler.timesteps):
																_lowerCAmelCase:Tuple									=  scheduler.scale_model_input(a__     ,a__)

																_lowerCAmelCase:List[str]									=  model(a__     ,a__)

																_lowerCAmelCase:int									=  scheduler.step(a__     ,a__     ,a__)
																_lowerCAmelCase:List[Any]									=  output.prev_sample

											_lowerCAmelCase:Tuple									=  torch.sum(torch.abs(a__))
											_lowerCAmelCase:Dict									=  torch.mean(torch.abs(a__))

											if torch_device in ["cpu", "mps"]:
																assert abs(result_sum.item() - 20.4125) < 1E-2
																assert abs(result_mean.item() - 0.0266) < 1E-3
											else:
																# CUDA
																assert abs(result_sum.item() - 20.4125) < 1E-2
																assert abs(result_mean.item() - 0.0266) < 1E-3







						def       __UpperCamelCase     (							self      :	Union[str, Any])						->       List[Any]:




											"""simple docstring"""







											if torch_device == "mps":
																return
											_lowerCAmelCase:str									=  self.scheduler_classes[0]
											_lowerCAmelCase:Optional[Any]									=  self.get_scheduler_config()
											_lowerCAmelCase:Any									=  scheduler_class(**a__)

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

											_lowerCAmelCase:Optional[int]									=  self.dummy_model()
											_lowerCAmelCase:Optional[Any]									=  self.dummy_sample_deter.to(a__) * scheduler.init_noise_sigma

											for t in scheduler.timesteps:
																_lowerCAmelCase:Union[str, Any]									=  scheduler.scale_model_input(a__     ,a__)

																_lowerCAmelCase:Tuple									=  model(a__     ,a__)

																_lowerCAmelCase:str									=  scheduler.step(a__     ,a__     ,a__)
																_lowerCAmelCase:Dict									=  output.prev_sample

											_lowerCAmelCase:Any									=  torch.sum(torch.abs(a__))
											_lowerCAmelCase:str									=  torch.mean(torch.abs(a__))

											if str(a__).startswith('''cpu'''):
																# The following sum varies between 148 and 156 on mps. Why?
																assert abs(result_sum.item() - 20.4125) < 1E-2
																assert abs(result_mean.item() - 0.0266) < 1E-3
											else:
																# CUDA
																assert abs(result_sum.item() - 20.4125) < 1E-2
																assert abs(result_mean.item() - 0.0266) < 1E-3






