



"""simple docstring"""


import math
import unittest

from transformers import BioGptConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

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


if is_torch_available():
				import torch

				from transformers import (
				    BioGptForCausalLM,
				    BioGptForSequenceClassification,
				    BioGptForTokenClassification,
				    BioGptModel,
				    BioGptTokenizer,
				)
				from transformers.models.biogpt.modeling_biogpt import BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST







class       A_			:



						"""simple docstring"""






						def __init__(					self :Optional[int]   ,  lowercase_ :Any   ,  lowercase_ :List[Any]=13   ,  lowercase_ :Dict=7   ,  lowercase_ :Dict=True   ,  lowercase_ :Dict=True   ,  lowercase_ :Any=False   ,  lowercase_ :List[Any]=True   ,  lowercase_ :Union[str, Any]=99   ,  lowercase_ :List[str]=32   ,  lowercase_ :Dict=5   ,  lowercase_ :str=4   ,  lowercase_ :Dict=37   ,  lowercase_ :Dict="gelu"   ,  lowercase_ :Any=0.1   ,  lowercase_ :Optional[int]=0.1   ,  lowercase_ :Tuple=5_12   ,  lowercase_ :int=16   ,  lowercase_ :int=2   ,  lowercase_ :List[Any]=0.02   ,  lowercase_ :Union[str, Any]=3   ,  lowercase_ :Optional[int]=4   ,  lowercase_ :str=None   ,  )				->			int:
												UpperCAmelCase             = parent
												UpperCAmelCase             = batch_size
												UpperCAmelCase             = seq_length
												UpperCAmelCase             = is_training
												UpperCAmelCase             = use_input_mask
												UpperCAmelCase             = use_token_type_ids
												UpperCAmelCase             = use_labels
												UpperCAmelCase             = vocab_size
												UpperCAmelCase             = hidden_size
												UpperCAmelCase             = num_hidden_layers
												UpperCAmelCase             = num_attention_heads
												UpperCAmelCase             = intermediate_size
												UpperCAmelCase             = hidden_act
												UpperCAmelCase             = hidden_dropout_prob
												UpperCAmelCase             = attention_probs_dropout_prob
												UpperCAmelCase             = max_position_embeddings
												UpperCAmelCase             = type_vocab_size
												UpperCAmelCase             = type_sequence_label_size
												UpperCAmelCase             = initializer_range
												UpperCAmelCase             = num_labels
												UpperCAmelCase             = num_choices
												UpperCAmelCase             = scope






						def 	UpperCAmelCase__     (					self :Optional[Any]					)				->			Tuple:
												UpperCAmelCase             = ids_tensor([self.batch_size, self.seq_length]   ,  self.vocab_size					)

												UpperCAmelCase             = None
												if self.use_input_mask:
																		UpperCAmelCase             = random_attention_mask([self.batch_size, self.seq_length]					)

												UpperCAmelCase             = None
												if self.use_token_type_ids:
																		UpperCAmelCase             = ids_tensor([self.batch_size, self.seq_length]   ,  self.type_vocab_size					)

												UpperCAmelCase             = None
												UpperCAmelCase             = None
												UpperCAmelCase             = None
												if self.use_labels:
																		UpperCAmelCase             = ids_tensor([self.batch_size]   ,  self.type_sequence_label_size					)
																		UpperCAmelCase             = ids_tensor([self.batch_size, self.seq_length]   ,  self.num_labels					)
																		UpperCAmelCase             = ids_tensor([self.batch_size]   ,  self.num_choices					)

												UpperCAmelCase             = self.get_config()

												return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels






						def 	UpperCAmelCase__     (					self :List[str]					)				->			List[str]:
												return BioGptConfig(
												    vocab_size=self.vocab_size   ,  hidden_size=self.hidden_size   ,  num_hidden_layers=self.num_hidden_layers   ,  num_attention_heads=self.num_attention_heads   ,  intermediate_size=self.intermediate_size   ,  hidden_act=self.hidden_act   ,  hidden_dropout_prob=self.hidden_dropout_prob   ,  attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,  max_position_embeddings=self.max_position_embeddings   ,  type_vocab_size=self.type_vocab_size   ,  is_decoder=lowercase_   ,  initializer_range=self.initializer_range   ,  )






						def 	UpperCAmelCase__     (					self :Optional[int]   ,  lowercase_ :str   ,  lowercase_ :List[Any]   ,  lowercase_ :Optional[Any]   ,  lowercase_ :str   ,  lowercase_ :Dict   ,  lowercase_ :Tuple   ,  lowercase_ :Dict					)				->			Dict:
												UpperCAmelCase             = BioGptModel(config=lowercase_					)
												model.to(lowercase_					)
												model.eval()
												UpperCAmelCase             = model(lowercase_   ,  attention_mask=lowercase_					)
												UpperCAmelCase             = model(lowercase_					)
												self.parent.assertEqual(result.last_hidden_state.shape   ,  (self.batch_size, self.seq_length, self.hidden_size)					)






						def 	UpperCAmelCase__     (					self :Union[str, Any]   ,  lowercase_ :List[Any]   ,  lowercase_ :Any   ,  lowercase_ :Optional[Any]   ,  lowercase_ :Tuple   ,  lowercase_ :str   ,  lowercase_ :Union[str, Any]   ,  lowercase_ :Tuple   ,  lowercase_ :Tuple   ,  lowercase_ :Dict   ,  )				->			int:
												UpperCAmelCase             = BioGptForCausalLM(config=lowercase_					)
												model.to(lowercase_					)
												model.eval()
												UpperCAmelCase             = model(lowercase_   ,  attention_mask=lowercase_   ,  token_type_ids=lowercase_   ,  labels=lowercase_					)
												self.parent.assertEqual(result.logits.shape   ,  (self.batch_size, self.seq_length, self.vocab_size)					)






						def 	UpperCAmelCase__     (					self :Union[str, Any]   ,  lowercase_ :Any   ,  lowercase_ :Tuple   ,  lowercase_ :int   ,  lowercase_ :int   ,  lowercase_ :List[Any]   ,  *lowercase_ :str					)				->			Any:
												UpperCAmelCase             = BioGptModel(config=lowercase_					)
												model.to(lowercase_					)
												model.eval()

												# create attention mask
												UpperCAmelCase             = torch.ones(input_ids.shape   ,  dtype=torch.long   ,  device=lowercase_					)
												UpperCAmelCase             = self.seq_length // 2
												UpperCAmelCase             = 0

												# first forward pass
												UpperCAmelCase      ,    UpperCAmelCase             = model(lowercase_   ,  attention_mask=lowercase_					).to_tuple()

												# create hypothetical next token and extent to next_input_ids
												UpperCAmelCase             = ids_tensor((self.batch_size, 1)   ,  config.vocab_size					)

												# change a random masked slice from input_ids
												UpperCAmelCase             = ids_tensor((1,)   ,  lowercase_					).item() + 1
												UpperCAmelCase             = ids_tensor((self.batch_size, 1)   ,  config.vocab_size					).squeeze(-1					)
												UpperCAmelCase             = random_other_next_tokens

												# append to next input_ids and attn_mask
												UpperCAmelCase             = torch.cat([input_ids, next_tokens]   ,  dim=-1					)
												UpperCAmelCase             = torch.cat(
												    [attn_mask, torch.ones((attn_mask.shape[0], 1)   ,  dtype=torch.long   ,  device=lowercase_					)]   ,  dim=1   ,  )

												# get two different outputs
												UpperCAmelCase             = model(lowercase_   ,  attention_mask=lowercase_					)['last_hidden_state']
												UpperCAmelCase             = model(lowercase_   ,  past_key_values=lowercase_   ,  attention_mask=lowercase_					)['last_hidden_state']

												# select random slice
												UpperCAmelCase             = ids_tensor((1,)   ,  output_from_past.shape[-1]					).item()
												UpperCAmelCase             = output_from_no_past[:, -1, random_slice_idx].detach()
												UpperCAmelCase             = 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 :Dict   ,  lowercase_ :List[Any]   ,  lowercase_ :Optional[Any]   ,  lowercase_ :Dict   ,  lowercase_ :Dict   ,  lowercase_ :List[Any]   ,  *lowercase_ :Dict					)				->			List[Any]:
												UpperCAmelCase             = BioGptModel(config=lowercase_					).to(lowercase_					).eval()

												UpperCAmelCase             = torch.ones(input_ids.shape   ,  dtype=torch.long   ,  device=lowercase_					)

												# first forward pass
												UpperCAmelCase             = model(lowercase_   ,  attention_mask=lowercase_   ,  use_cache=lowercase_					)

												UpperCAmelCase      ,    UpperCAmelCase             = outputs.to_tuple()

												# create hypothetical multiple next token and extent to next_input_ids
												UpperCAmelCase             = ids_tensor((self.batch_size, 3)   ,  config.vocab_size					)
												UpperCAmelCase             = ids_tensor((self.batch_size, 3)   ,  2					)

												# append to next input_ids and
												UpperCAmelCase             = torch.cat([input_ids, next_tokens]   ,  dim=-1					)
												UpperCAmelCase             = torch.cat([attention_mask, next_attn_mask]   ,  dim=-1					)

												UpperCAmelCase             = model(lowercase_   ,  attention_mask=lowercase_					)['last_hidden_state']
												UpperCAmelCase             = model(lowercase_   ,  attention_mask=lowercase_   ,  past_key_values=lowercase_					)[
												    'last_hidden_state'
												]

												# select random slice
												UpperCAmelCase             = ids_tensor((1,)   ,  output_from_past.shape[-1]					).item()
												UpperCAmelCase             = output_from_no_past[:, -3:, random_slice_idx].detach()
												UpperCAmelCase             = output_from_past[:, :, random_slice_idx].detach()

												self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]					)

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






						def 	UpperCAmelCase__     (					self :Any   ,  lowercase_ :List[str]   ,  lowercase_ :List[Any]   ,  lowercase_ :int   ,  lowercase_ :Optional[Any]   ,  lowercase_ :int   ,  *lowercase_ :List[str]   ,  lowercase_ :Union[str, Any]=False					)				->			Optional[int]:
												UpperCAmelCase             = BioGptForCausalLM(lowercase_					)
												model.to(lowercase_					)
												if gradient_checkpointing:
																		model.gradient_checkpointing_enable()

												UpperCAmelCase             = model(lowercase_   ,  labels=lowercase_					)
												self.parent.assertEqual(result.loss.shape   ,  ()					)
												self.parent.assertEqual(result.logits.shape   ,  (self.batch_size, self.seq_length, self.vocab_size)					)
												result.loss.backward()






						def 	UpperCAmelCase__     (					self :Any   ,  lowercase_ :Union[str, Any]   ,  *lowercase_ :int					)				->			Tuple:
												UpperCAmelCase             = BioGptModel(lowercase_					)
												UpperCAmelCase             = model.config.initializer_range / math.sqrt(2 * model.config.num_hidden_layers					)
												for key in model.state_dict().keys():
																		if "c_proj" in key and "weight" in key:
																								self.parent.assertLessEqual(abs(torch.std(model.state_dict()[key]					) - model_std					)   ,  0.001					)
																								self.parent.assertLessEqual(abs(torch.mean(model.state_dict()[key]					) - 0.0					)   ,  0.01					)






						def 	UpperCAmelCase__     (					self :Dict   ,  lowercase_ :Optional[int]   ,  lowercase_ :List[str]   ,  lowercase_ :Optional[Any]   ,  lowercase_ :Any   ,  lowercase_ :List[str]   ,  *lowercase_ :Dict					)				->			int:
												UpperCAmelCase             = self.num_labels
												UpperCAmelCase             = BioGptForTokenClassification(lowercase_					)
												model.to(lowercase_					)
												model.eval()
												UpperCAmelCase             = model(lowercase_   ,  attention_mask=lowercase_   ,  token_type_ids=lowercase_					)
												self.parent.assertEqual(result.logits.shape   ,  (self.batch_size, self.seq_length, self.num_labels)					)






						def 	UpperCAmelCase__     (					self :str					)				->			str:
												UpperCAmelCase             = self.prepare_config_and_inputs()
												(
												    (
												    UpperCAmelCase
												)      ,    (
												    UpperCAmelCase
												)      ,    (
												    UpperCAmelCase
												)      ,    (
												    UpperCAmelCase
												)      ,    (
												    UpperCAmelCase
												)      ,    (
												    UpperCAmelCase
												)      ,    (
												    UpperCAmelCase
												)      ,    
												)             = config_and_inputs
												UpperCAmelCase             = {'input_ids': input_ids, 'attention_mask': input_mask}
												return config, inputs_dict







@require_torch
class       A_			(     SCREAMING_SNAKE_CASE_	,   SCREAMING_SNAKE_CASE_	,   SCREAMING_SNAKE_CASE_	,   unittest.TestCase				):



						"""simple docstring"""
						__UpperCamelCase						=							(
						    (BioGptModel, BioGptForCausalLM, BioGptForSequenceClassification, BioGptForTokenClassification)
						    if is_torch_available()
						    else ()
						)
						__UpperCamelCase						=							(BioGptForCausalLM,) if is_torch_available() else ()
						__UpperCamelCase						=							(
						    {
						        """feature-extraction""": BioGptModel,
						        """text-classification""": BioGptForSequenceClassification,
						        """text-generation""": BioGptForCausalLM,
						        """token-classification""": BioGptForTokenClassification,
						        """zero-shot""": BioGptForSequenceClassification,
						    }
						    if is_torch_available()
						    else {}
						)
						__UpperCamelCase						=							False






						def 	UpperCAmelCase__     (					self :int					)				->			Optional[Any]:
												UpperCAmelCase             = BioGptModelTester(self					)
												UpperCAmelCase             = ConfigTester(self   ,  config_class=lowercase_   ,  hidden_size=37					)






						def 	UpperCAmelCase__     (					self :int					)				->			List[str]:
												self.config_tester.run_common_tests()






						def 	UpperCAmelCase__     (					self :str					)				->			str:
												UpperCAmelCase             = self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*lowercase_					)






						def 	UpperCAmelCase__     (					self :Dict					)				->			Optional[Any]:
												UpperCAmelCase             = self.model_tester.prepare_config_and_inputs()
												for type in ["absolute", "relative_key", "relative_key_query"]:
																		UpperCAmelCase             = type
																		self.model_tester.create_and_check_model(*lowercase_					)






						def 	UpperCAmelCase__     (					self :List[str]					)				->			List[str]:
												UpperCAmelCase             = self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_biogpt_model_attention_mask_past(*lowercase_					)






						def 	UpperCAmelCase__     (					self :List[str]					)				->			Any:
												UpperCAmelCase             = self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_forward_and_backwards(*lowercase_   ,  gradient_checkpointing=lowercase_					)






						def 	UpperCAmelCase__     (					self :Optional[int]					)				->			Dict:
												UpperCAmelCase             = self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_biogpt_model_past_large_inputs(*lowercase_					)






						def 	UpperCAmelCase__     (					self :str					)				->			List[Any]:
												UpperCAmelCase             = self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_biogpt_weight_initialization(*lowercase_					)






						def 	UpperCAmelCase__     (					self :List[Any]					)				->			Dict:
												UpperCAmelCase             = self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_biogpt_for_token_classification(*lowercase_					)






						@slow
						def 	UpperCAmelCase__     (					self :Optional[int]					)				->			Any:
												UpperCAmelCase             = BioGptForCausalLM.from_pretrained('microsoft/biogpt'					)
												model.to(lowercase_					)
												UpperCAmelCase             = BioGptTokenizer.from_pretrained('microsoft/biogpt'					)

												UpperCAmelCase             = 'left'

												# Define PAD Token = EOS Token = 50256
												UpperCAmelCase             = tokenizer.eos_token
												UpperCAmelCase             = model.config.eos_token_id

												# use different length sentences to test batching
												UpperCAmelCase             = [
												    'Hello, my dog is a little',
												    'Today, I',
												]

												UpperCAmelCase             = tokenizer(lowercase_   ,  return_tensors='pt'   ,  padding=lowercase_					)
												UpperCAmelCase             = inputs['input_ids'].to(lowercase_					)

												UpperCAmelCase             = model.generate(
												    input_ids=lowercase_   ,  attention_mask=inputs['attention_mask'].to(lowercase_					)   ,  )

												UpperCAmelCase             = tokenizer(sentences[0]   ,  return_tensors='pt'					).input_ids.to(lowercase_					)
												UpperCAmelCase             = model.generate(input_ids=lowercase_					)

												UpperCAmelCase             = inputs_non_padded.shape[-1] - inputs['attention_mask'][-1].long().sum().cpu().item()
												UpperCAmelCase             = tokenizer(sentences[1]   ,  return_tensors='pt'					).input_ids.to(lowercase_					)
												UpperCAmelCase             = model.generate(input_ids=lowercase_   ,  max_length=model.config.max_length - num_paddings					)

												UpperCAmelCase             = tokenizer.batch_decode(lowercase_   ,  skip_special_tokens=lowercase_					)
												UpperCAmelCase             = tokenizer.decode(output_non_padded[0]   ,  skip_special_tokens=lowercase_					)
												UpperCAmelCase             = tokenizer.decode(output_padded[0]   ,  skip_special_tokens=lowercase_					)

												UpperCAmelCase             = [
												    'Hello, my dog is a little bit bigger than a little bit.',
												    'Today, I have a good idea of how to use the information',
												]
												self.assertListEqual(lowercase_   ,  lowercase_					)
												self.assertListEqual(lowercase_   ,  [non_padded_sentence, padded_sentence]					)






						@slow
						def 	UpperCAmelCase__     (					self :Tuple					)				->			Any:
												for model_name in BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		UpperCAmelCase             = BioGptModel.from_pretrained(lowercase_					)
																		self.assertIsNotNone(lowercase_					)






						def 	UpperCAmelCase__     (					self :Optional[int]					)				->			Union[str, Any]:
												UpperCAmelCase      ,    UpperCAmelCase             = self.model_tester.prepare_config_and_inputs_for_common()
												UpperCAmelCase             = 3
												UpperCAmelCase             = input_dict['input_ids']
												UpperCAmelCase             = input_ids.ne(1					).to(lowercase_					)
												UpperCAmelCase             = ids_tensor([self.model_tester.batch_size]   ,  self.model_tester.type_sequence_label_size					)
												UpperCAmelCase             = BioGptForSequenceClassification(lowercase_					)
												model.to(lowercase_					)
												model.eval()
												UpperCAmelCase             = model(lowercase_   ,  attention_mask=lowercase_   ,  labels=lowercase_					)
												self.assertEqual(result.logits.shape   ,  (self.model_tester.batch_size, self.model_tester.num_labels)					)






						def 	UpperCAmelCase__     (					self :List[str]					)				->			Union[str, Any]:
												UpperCAmelCase      ,    UpperCAmelCase             = self.model_tester.prepare_config_and_inputs_for_common()
												UpperCAmelCase             = 3
												UpperCAmelCase             = 'multi_label_classification'
												UpperCAmelCase             = input_dict['input_ids']
												UpperCAmelCase             = input_ids.ne(1					).to(lowercase_					)
												UpperCAmelCase             = ids_tensor(
												    [self.model_tester.batch_size, config.num_labels]   ,  self.model_tester.type_sequence_label_size					).to(torch.float					)
												UpperCAmelCase             = BioGptForSequenceClassification(lowercase_					)
												model.to(lowercase_					)
												model.eval()
												UpperCAmelCase             = model(lowercase_   ,  attention_mask=lowercase_   ,  labels=lowercase_					)
												self.assertEqual(result.logits.shape   ,  (self.model_tester.batch_size, self.model_tester.num_labels)					)







@require_torch
class       A_			(     unittest.TestCase				):



						"""simple docstring"""






						@slow
						def 	UpperCAmelCase__     (					self :List[Any]					)				->			Tuple:
												UpperCAmelCase             = BioGptForCausalLM.from_pretrained('microsoft/biogpt'					)
												UpperCAmelCase             = torch.tensor([[2, 48_05, 9, 6_56, 21]]					)
												UpperCAmelCase             = model(lowercase_					)[0]

												UpperCAmelCase             = 4_23_84

												UpperCAmelCase             = torch.Size((1, 5, vocab_size)					)
												self.assertEqual(output.shape   ,  lowercase_					)

												UpperCAmelCase             = torch.tensor(
												    [[[-9.5236, -9.8918, 10.4557], [-11.0469, -9.6423, 8.1022], [-8.8664, -7.8826, 5.5325]]]					)

												self.assertTrue(torch.allclose(output[:, :3, :3]   ,  lowercase_   ,  atol=1E-4					)					)






						@slow
						def 	UpperCAmelCase__     (					self :Tuple					)				->			Any:
												UpperCAmelCase             = BioGptTokenizer.from_pretrained('microsoft/biogpt'					)
												UpperCAmelCase             = BioGptForCausalLM.from_pretrained('microsoft/biogpt'					)
												model.to(lowercase_					)

												torch.manual_seed(0					)
												UpperCAmelCase             = tokenizer('COVID-19 is'   ,  return_tensors='pt'					).to(lowercase_					)
												UpperCAmelCase             = model.generate(
												    **lowercase_   ,  min_length=1_00   ,  max_length=10_24   ,  num_beams=5   ,  early_stopping=lowercase_   ,  )
												UpperCAmelCase             = tokenizer.decode(output_ids[0]   ,  skip_special_tokens=lowercase_					)

												UpperCAmelCase             = (
												    'COVID-19 is a global pandemic caused by severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2), the'
												    ' causative agent of coronavirus disease 2019 (COVID-19), which has spread to more than 200 countries and'
												    ' territories, including the United States (US), Canada, Australia, New Zealand, the United Kingdom (UK),'
												    ' and the United States of America (USA), as of March 11, 2020, with more than 800,000 confirmed cases and'
												    ' more than 800,000 deaths.'
												)
												self.assertEqual(lowercase_   ,  lowercase_					)








import os

import pytest
import yaml

from datasets.features.features import Features, Value
from datasets.info import DatasetInfo, DatasetInfosDict

@pytest.mark.parametrize(
    """files"""    ,      [
        ["""full:README.md""", """dataset_infos.json"""],
        ["""empty:README.md""", """dataset_infos.json"""],
        ["""dataset_infos.json"""],
        ["""full:README.md"""],
    ]    ,      )
def 						UpperCamelCase					(lowercase_: List[str]    ,      lowercase_: Optional[int]					)     ->      List[str]:
	A__							:    Tuple        =		tmp_path_factory.mktemp("""dset_infos_dir"""					)
	if "full:README.md" in files:
		with open(dataset_infos_dir / """README.md"""    ,      """w"""					) as f:
			f.write("""---\ndataset_info:\n  dataset_size: 42\n---"""					)
	if "empty:README.md" in files:
		with open(dataset_infos_dir / """README.md"""    ,      """w"""					) as f:
			f.write(""""""					)
    # we want to support dataset_infos.json for backward compatibility
	if "dataset_infos.json" in files:
		with open(dataset_infos_dir / """dataset_infos.json"""    ,      """w"""					) as f:
			f.write("""{\"default\": {\"dataset_size\": 42}}"""					)
	A__							:    List[Any]        =		DatasetInfosDict.from_directory(lowercase_					)
	assert dataset_infos
	assert dataset_infos["default"].dataset_size == 42

@pytest.mark.parametrize(
    """dataset_info"""    ,      [
        DatasetInfo(),
        DatasetInfo(
            description="""foo"""    ,      features=Features({"""a""": Value("""int32"""					)}					)    ,      builder_name="""builder"""    ,      config_name="""config"""    ,      version="""1.0.0"""    ,      splits=[{"""name""": """train"""}]    ,      download_size=42    ,      ),
    ]    ,      )
def 						UpperCamelCase					(lowercase_: str    ,      lowercase_: DatasetInfo					)     ->      List[Any]:
	A__							:    Union[str, Any]        =		str(lowercase_					)
	dataset_info.write_to_directory(lowercase_					)
	A__							:    List[Any]        =		DatasetInfo.from_directory(lowercase_					)
	assert dataset_info == reloaded
	assert os.path.exists(os.path.join(lowercase_    ,      """dataset_info.json"""					)					)

def 						UpperCamelCase					()     ->      List[Any]:
	A__							:    Union[str, Any]        =		DatasetInfo(
	    description="""foo"""    ,      citation="""bar"""    ,      homepage="""https://foo.bar"""    ,      license="""CC0"""    ,      features=Features({"""a""": Value("""int32"""					)}					)    ,      post_processed={}    ,      supervised_keys=()    ,      task_templates=[]    ,      builder_name="""builder"""    ,      config_name="""config"""    ,      version="""1.0.0"""    ,      splits=[{"""name""": """train""", """num_examples""": 42}]    ,      download_checksums={}    ,      download_size=1337    ,      post_processing_size=442    ,      dataset_size=1234    ,      size_in_bytes=1337 + 442 + 1234    ,      )
	A__							:    Dict        =		dataset_info._to_yaml_dict()
	assert sorted(lowercase_					) == sorted(DatasetInfo._INCLUDED_INFO_IN_YAML					)
	for key in DatasetInfo._INCLUDED_INFO_IN_YAML:
		assert key in dataset_info_yaml_dict
		assert isinstance(dataset_info_yaml_dict[key]    ,      (list, dict, int, str)					)
	A__							:    Union[str, Any]        =		yaml.safe_dump(lowercase_					)
	A__							:    List[Any]        =		yaml.safe_load(lowercase_					)
	assert dataset_info_yaml_dict == reloaded

def 						UpperCamelCase					()     ->      List[str]:
	A__							:    Optional[int]        =		DatasetInfo()
	A__							:    List[Any]        =		dataset_info._to_yaml_dict()
	assert dataset_info_yaml_dict == {}


@pytest.mark.parametrize(
    """dataset_infos_dict"""    ,      [
        DatasetInfosDict(),
        DatasetInfosDict({"""default""": DatasetInfo()}					),
        DatasetInfosDict({"""my_config_name""": DatasetInfo()}					),
        DatasetInfosDict(
            {
                """default""": DatasetInfo(
                    description="""foo"""    ,      features=Features({"""a""": Value("""int32"""					)}					)    ,      builder_name="""builder"""    ,      config_name="""config"""    ,      version="""1.0.0"""    ,      splits=[{"""name""": """train"""}]    ,      download_size=42    ,      )
            }					),
        DatasetInfosDict(
            {
                """v1""": DatasetInfo(dataset_size=42					),
                """v2""": DatasetInfo(dataset_size=1337					),
            }					),
    ]    ,      )
def 						UpperCamelCase					(lowercase_: Tuple    ,      lowercase_: DatasetInfosDict					)     ->      Optional[Any]:
	A__							:    List[Any]        =		str(lowercase_					)
	dataset_infos_dict.write_to_directory(lowercase_					)
	A__							:    Dict        =		DatasetInfosDict.from_directory(lowercase_					)

	# the config_name of the dataset_infos_dict take over the attribute
	for config_name, dataset_info in dataset_infos_dict.items():
		A__							:    Optional[int]        =		config_name
		# the yaml representation doesn't include fields like description or citation
		# so we just test that we can recover what we can from the yaml
		A__							:    List[str]        =		DatasetInfo._from_yaml_dict(dataset_info._to_yaml_dict()					)
	assert dataset_infos_dict == reloaded

	if dataset_infos_dict:
		assert os.path.exists(os.path.join(lowercase_    ,      """README.md"""					)					)



