code: 
  
  
  '''simple docstring'''
  
  
  
  from copy import deepcopy
  from unittest.case import TestCase
  
  import pytest
  
  from datasets.arrow_dataset import Dataset
  from datasets.features import Audio, ClassLabel, Features, Image, Sequence, Value
  from datasets.info import DatasetInfo
  from datasets.tasks import (
      AudioClassification,
      AutomaticSpeechRecognition,
      ImageClassification,
      LanguageModeling,
      QuestionAnsweringExtractive,
      Summarization,
      TextClassification,
      task_template_from_dict,
  )
  from datasets.utils.py_utils import asdict
  
  
  __lowercase			:		List[Any] =			{
      'id': '5733be284776f41900661182',
      'title': 'University_of_Notre_Dame',
      'context': 'Architecturally, the school has a Catholic character. Atop the Main Building\'s gold dome is a golden statue of the Virgin Mary. Immediately in front of the Main Building and facing it, is a copper statue of Christ with arms upraised with the legend "Venite Ad Me Omnes". Next to the Main Building is the Basilica of the Sacred Heart. Immediately behind the basilica is the Grotto, a Marian place of prayer and reflection. It is a replica of the grotto at Lourdes, France where the Virgin Mary reputedly appeared to Saint Bernadette Soubirous in 1858. At the end of the main drive (and in a direct line that connects through 3 statues and the Gold Dome), is a simple, modern stone statue of Mary.',
      'question': 'To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France?',
      'answers': {'text': ['Saint Bernadette Soubirous'], 'answer_start': [5_15]},
  }
  
  
  
  
  
  
  @pytest.mark.parametrize(
      'task_cls'		,   [
          AudioClassification,
          AutomaticSpeechRecognition,
          ImageClassification,
          LanguageModeling,
          QuestionAnsweringExtractive,
          Summarization,
          TextClassification,
      ]		,   )
  def 						lowerCamelCase							(_SCREAMING_SNAKE_CASE   :     int     ):
  					__a    : int      					=						task_cls()
  					__a    : Dict      					=						asdict(_SCREAMING_SNAKE_CASE     )
  					__a    : int      					=						task_template_from_dict(_SCREAMING_SNAKE_CASE     )
  					assert task == reloaded
  
  
  
  
  
  class 							__UpperCamelCase       :
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Dict      					=						LanguageModeling(text_column='input_text'							)
  						assert {"input_text": "text"} == task.column_mapping
  
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : str      					=						Features({'text': Value('string'							)}							)
  						__a    : List[Any]      					=						{'text_column': 'input_text'}
  						__a    : Dict      					=						LanguageModeling.from_dict(__a							)
  						assert "language-modeling" == task.task
  						assert input_schema == task.input_schema
  
  
  
  
  
  class 							__UpperCamelCase       (	lowerCAmelCase_      ):
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Any      					=						sorted(['pos', 'neg']							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : List[str]      					=						TextClassification(text_column='input_text'		,       label_column='input_label'							)
  						self.assertDictEqual({'input_text': 'text', 'input_label': 'labels'}		,       task.column_mapping							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[int]      					=						Features({'text': Value('string'							)}							)
  						# Labels are cast to tuple during `TextClassification.__post_init__`, so we do the same here
  						__a    : Any      					=						Features({'labels': ClassLabel}							)
  						__a    : List[str]      					=						{'text_column': 'input_text', 'label_column': 'input_labels'}
  						__a    : str      					=						TextClassification.from_dict(__a							)
  						self.assertEqual('text-classification'		,       task.task							)
  						self.assertEqual(__a		,       task.input_schema							)
  						self.assertEqual(__a		,       task.label_schema							)
  
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Any      					=						TextClassification(text_column='input_text'		,       label_column='input_label'							)
  						self.assertEqual(task.label_schema['labels']		,       __a							)
  						__a    : int      					=						task.align_with_features(Features({'input_label': ClassLabel(names=self.labels							)}							)							)
  						self.assertEqual(task.label_schema['labels']		,       ClassLabel(names=self.labels							)							)
  
  
  
  
  
  class 							__UpperCamelCase       (	lowerCAmelCase_      ):
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : str      					=						QuestionAnsweringExtractive(
  						    context_column='input_context'		,       question_column='input_question'		,       answers_column='input_answers'							)
  						self.assertDictEqual(
  						    {'input_context': 'context', 'input_question': 'question', 'input_answers': 'answers'}		,       task.column_mapping							)
  
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Dict      					=						Features({'question': Value('string'							), 'context': Value('string'							)}							)
  						__a    : Optional[int]      					=						Features(
  						    {
  						        'answers': Sequence(
  						            {
  						                'text': Value('string'							),
  						                'answer_start': Value('int32'							),
  						            }							)
  						    }							)
  						__a    : Optional[int]      					=						{
  						    'context_column': 'input_input_context',
  						    'question_column': 'input_question',
  						    'answers_column': 'input_answers',
  						}
  						__a    : int      					=						QuestionAnsweringExtractive.from_dict(__a							)
  						self.assertEqual('question-answering-extractive'		,       task.task							)
  						self.assertEqual(__a		,       task.input_schema							)
  						self.assertEqual(__a		,       task.label_schema							)
  
  
  
  
  
  class 							__UpperCamelCase       (	lowerCAmelCase_      ):
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : List[str]      					=						Summarization(text_column='input_text'		,       summary_column='input_summary'							)
  						self.assertDictEqual({'input_text': 'text', 'input_summary': 'summary'}		,       task.column_mapping							)
  
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[int]      					=						Features({'text': Value('string'							)}							)
  						__a    : Any      					=						Features({'summary': Value('string'							)}							)
  						__a    : Tuple      					=						{'text_column': 'input_text', 'summary_column': 'input_summary'}
  						__a    : Tuple      					=						Summarization.from_dict(__a							)
  						self.assertEqual('summarization'		,       task.task							)
  						self.assertEqual(__a		,       task.input_schema							)
  						self.assertEqual(__a		,       task.label_schema							)
  
  
  
  
  
  class 							__UpperCamelCase       (	lowerCAmelCase_      ):
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Any      					=						AutomaticSpeechRecognition(audio_column='input_audio'		,       transcription_column='input_transcription'							)
  						self.assertDictEqual({'input_audio': 'audio', 'input_transcription': 'transcription'}		,       task.column_mapping							)
  
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[int]      					=						Features({'audio': Audio()}							)
  						__a    : Tuple      					=						Features({'transcription': Value('string'							)}							)
  						__a    : List[str]      					=						{
  						    'audio_column': 'input_audio',
  						    'transcription_column': 'input_transcription',
  						}
  						__a    : Tuple      					=						AutomaticSpeechRecognition.from_dict(__a							)
  						self.assertEqual('automatic-speech-recognition'		,       task.task							)
  						self.assertEqual(__a		,       task.input_schema							)
  						self.assertEqual(__a		,       task.label_schema							)
  
  
  
  
  
  class 							__UpperCamelCase       (	lowerCAmelCase_      ):
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Tuple      					=						sorted(['pos', 'neg']							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[Any]      					=						AudioClassification(audio_column='input_audio'		,       label_column='input_label'							)
  						self.assertDictEqual({'input_audio': 'audio', 'input_label': 'labels'}		,       task.column_mapping							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : List[Any]      					=						Features({'audio': Audio()}							)
  						__a    : Dict      					=						Features({'labels': ClassLabel}							)
  						__a    : Union[str, Any]      					=						{
  						    'audio_column': 'input_image',
  						    'label_column': 'input_label',
  						}
  						__a    : Optional[int]      					=						AudioClassification.from_dict(__a							)
  						self.assertEqual('audio-classification'		,       task.task							)
  						self.assertEqual(__a		,       task.input_schema							)
  						self.assertEqual(__a		,       task.label_schema							)
  
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Dict      					=						AudioClassification(audio_column='input_audio'		,       label_column='input_label'							)
  						self.assertEqual(task.label_schema['labels']		,       __a							)
  						__a    : int      					=						task.align_with_features(Features({'input_label': ClassLabel(names=self.labels							)}							)							)
  						self.assertEqual(task.label_schema['labels']		,       ClassLabel(names=self.labels							)							)
  
  
  
  
  
  class 							__UpperCamelCase       (	lowerCAmelCase_      ):
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : str      					=						sorted(['pos', 'neg']							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[Any]      					=						ImageClassification(image_column='input_image'		,       label_column='input_label'							)
  						self.assertDictEqual({'input_image': 'image', 'input_label': 'labels'}		,       task.column_mapping							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[int]      					=						Features({'image': Image()}							)
  						__a    : List[str]      					=						Features({'labels': ClassLabel}							)
  						__a    : Union[str, Any]      					=						{
  						    'image_column': 'input_image',
  						    'label_column': 'input_label',
  						}
  						__a    : Optional[int]      					=						ImageClassification.from_dict(__a							)
  						self.assertEqual('image-classification'		,       task.task							)
  						self.assertEqual(__a		,       task.input_schema							)
  						self.assertEqual(__a		,       task.label_schema							)
  
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : List[Any]      					=						ImageClassification(image_column='input_image'		,       label_column='input_label'							)
  						self.assertEqual(task.label_schema['labels']		,       __a							)
  						__a    : Optional[Any]      					=						task.align_with_features(Features({'input_label': ClassLabel(names=self.labels							)}							)							)
  						self.assertEqual(task.label_schema['labels']		,       ClassLabel(names=self.labels							)							)
  
  
  
  
  
  class 							__UpperCamelCase       (	lowerCAmelCase_      ):
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Union[str, Any]      					=						DatasetInfo(task_templates=QuestionAnsweringExtractive()							)
  						__a    : Optional[int]      					=						Dataset.from_dict({k: [v] for k, v in SAMPLE_QUESTION_ANSWERING_EXTRACTIVE.items()}		,       info=__a							)
  						assert isinstance(dataset.info.task_templates		,       __a							)
  						assert len(dataset.info.task_templates							) == 1
  
  						def keep_task(__a							):
  											return x
  
  						def dont_keep_task(__a							):
  											__a    : Any      					=						deepcopy(__a							)
  											__a    : Tuple      					=						0
  											return out
  
  						__a    : Tuple      					=						dataset.map(__a							)
  						assert mapped_dataset.info.task_templates == dataset.info.task_templates
  						# reload from cache
  						__a    : Dict      					=						dataset.map(__a							)
  						assert mapped_dataset.info.task_templates == dataset.info.task_templates
  
  						__a    : Any      					=						dataset.map(__a							)
  						assert mapped_dataset.info.task_templates == []
  						# reload from cache
  						__a    : Union[str, Any]      					=						dataset.map(__a							)
  						assert mapped_dataset.info.task_templates == []
  
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Any      					=						Features({'text': Value('string'							), 'label': ClassLabel(names=('pos', 'neg')							)}							)
  						__a    : List[Any]      					=						TextClassification(text_column='text'		,       label_column='label'							)
  						__a    : Dict      					=						DatasetInfo(features=__a		,       task_templates=__a							)
  						__a    : Optional[int]      					=						Dataset.from_dict({'text': ['A sentence.'], 'label': ['pos']}		,       info=__a							)
  
  						def process(__a							):
  											return example
  
  						__a    : Dict      					=						dataset.remove_columns('label'							)
  						__a    : Optional[int]      					=						modified_dataset.map(__a							)
  						assert mapped_dataset.info.task_templates == []
  
  
  
  
style_context: 
  
  
  '''simple docstring'''
  
  
  
  import torch
  
  from diffusers import KDPMaAncestralDiscreteScheduler
  from diffusers.utils import torch_device
  
  from .test_schedulers import SchedulerCommonTest
  
  
  
  
  
  class 							__UpperCamelCase       (	lowerCAmelCase_      ):
  	A_			    =					(KDPMaAncestralDiscreteScheduler,)
  	A_			    =					10
  
  
  
  
  	def    __UpperCAmelCase							(     self		,       **__a							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Dict      					=						{
  						    'num_train_timesteps': 1100,
  						    'beta_start': 0.0001,
  						    'beta_end': 0.02,
  						    'beta_schedule': 'linear',
  						}
  
  						config.update(**__a							)
  						return config
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						for timesteps in [10, 50, 100, 1000]:
  											self.check_over_configs(num_train_timesteps=__a							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''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							):
  
  						'''simple docstring'''
  
  
  
  
  
  						for schedule in ["linear", "scaled_linear"]:
  											self.check_over_configs(beta_schedule=__a							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						if torch_device == "mps":
  											return
  						__a    : Dict      					=						self.scheduler_classes[0]
  						__a    : Tuple      					=						self.get_scheduler_config()
  						__a    : Optional[int]      					=						scheduler_class(**__a							)
  
  						scheduler.set_timesteps(self.num_inference_steps							)
  
  						__a    : int      					=						torch.manual_seed(0							)
  
  						__a    : Dict      					=						self.dummy_model()
  						__a    : List[Any]      					=						self.dummy_sample_deter * scheduler.init_noise_sigma
  						__a    : int      					=						sample.to(__a							)
  
  						for i, t in enumerate(scheduler.timesteps							):
  											__a    : Any      					=						scheduler.scale_model_input(__a		,       __a							)
  
  											__a    : int      					=						model(__a		,       __a							)
  
  											__a    : Dict      					=						scheduler.step(__a		,       __a		,       __a		,       generator=__a							)
  											__a    : int      					=						output.prev_sample
  
  						__a    : Tuple      					=						torch.sum(torch.abs(__a							)							)
  						__a    : List[str]      					=						torch.mean(torch.abs(__a							)							)
  
  						assert abs(result_sum.item() - 13849.3877							) < 1E-2
  						assert abs(result_mean.item() - 18.0331							) < 5E-3
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						for prediction_type in ["epsilon", "v_prediction"]:
  											self.check_over_configs(prediction_type=__a							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						if torch_device == "mps":
  											return
  						__a    : Dict      					=						self.scheduler_classes[0]
  						__a    : Dict      					=						self.get_scheduler_config(prediction_type='v_prediction'							)
  						__a    : List[str]      					=						scheduler_class(**__a							)
  
  						scheduler.set_timesteps(self.num_inference_steps							)
  
  						__a    : Dict      					=						self.dummy_model()
  						__a    : List[str]      					=						self.dummy_sample_deter * scheduler.init_noise_sigma
  						__a    : List[str]      					=						sample.to(__a							)
  
  						__a    : Tuple      					=						torch.manual_seed(0							)
  
  						for i, t in enumerate(scheduler.timesteps							):
  											__a    : List[Any]      					=						scheduler.scale_model_input(__a		,       __a							)
  
  											__a    : Optional[int]      					=						model(__a		,       __a							)
  
  											__a    : Union[str, Any]      					=						scheduler.step(__a		,       __a		,       __a		,       generator=__a							)
  											__a    : Union[str, Any]      					=						output.prev_sample
  
  						__a    : Any      					=						torch.sum(torch.abs(__a							)							)
  						__a    : Optional[int]      					=						torch.mean(torch.abs(__a							)							)
  
  						assert abs(result_sum.item() - 328.9970							) < 1E-2
  						assert abs(result_mean.item() - 0.4284							) < 1E-3
  
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						if torch_device == "mps":
  											return
  						__a    : List[str]      					=						self.scheduler_classes[0]
  						__a    : Union[str, Any]      					=						self.get_scheduler_config()
  						__a    : List[Any]      					=						scheduler_class(**__a							)
  
  						scheduler.set_timesteps(self.num_inference_steps		,       device=__a							)
  						__a    : Union[str, Any]      					=						torch.manual_seed(0							)
  
  						__a    : List[str]      					=						self.dummy_model()
  						__a    : Any      					=						self.dummy_sample_deter.to(__a							) * scheduler.init_noise_sigma
  
  						for t in scheduler.timesteps:
  											__a    : List[Any]      					=						scheduler.scale_model_input(__a		,       __a							)
  
  											__a    : str      					=						model(__a		,       __a							)
  
  											__a    : str      					=						scheduler.step(__a		,       __a		,       __a		,       generator=__a							)
  											__a    : Any      					=						output.prev_sample
  
  						__a    : Union[str, Any]      					=						torch.sum(torch.abs(__a							)							)
  						__a    : str      					=						torch.mean(torch.abs(__a							)							)
  
  						assert abs(result_sum.item() - 13849.3818							) < 1E-1
  						assert abs(result_mean.item() - 18.0331							) < 1E-3
  
  
  
  