


"""simple docstring"""




import argparse
import collections
import json
import os
import re
import string
import sys

import numpy as np


lowercase_			     =  re.compile(r"\b(a|an|the)\b", re.UNICODE)

lowercase_			     =  None

def        lowercase							(		) ->      Any:
		__a           =			argparse.ArgumentParser('''Official evaluation script for SQuAD version 2.0.'''			)
		parser.add_argument('''data_file'''    ,					metavar='''data.json'''    ,					help='''Input data JSON file.'''			)
		parser.add_argument('''pred_file'''    ,					metavar='''pred.json'''    ,					help='''Model predictions.'''			)
		parser.add_argument(
		    '''--out-file'''    ,					'''-o'''    ,					metavar='''eval.json'''    ,					help='''Write accuracy metrics to file (default is stdout).'''			)
		parser.add_argument(
		    '''--na-prob-file'''    ,					'''-n'''    ,					metavar='''na_prob.json'''    ,					help='''Model estimates of probability of no answer.'''			)
		parser.add_argument(
		    '''--na-prob-thresh'''    ,					'''-t'''    ,					type=lowerCAmelCase__    ,					default=1.0    ,					help='''Predict "" if no-answer probability exceeds this (default = 1.0).'''    ,					)
		parser.add_argument(
		    '''--out-image-dir'''    ,					'''-p'''    ,					metavar='''out_images'''    ,					default=lowerCAmelCase__    ,					help='''Save precision-recall curves to directory.'''			)
		parser.add_argument('''--verbose'''    ,					'''-v'''    ,					action='''store_true'''			)
		if len(sys.argv			) == 1:
				parser.print_help()
				sys.exit(1			)
		return parser.parse_args()

def        lowercase							(		lowerCAmelCase__ :     Union[str, Any]			) ->      Optional[Any]:
		__a           =			{}
		for article in dataset:
				for p in article["paragraphs"]:
						for qa in p["qas"]:
								__a           =			bool(qa['''answers''']['''text''']			)
		return qid_to_has_ans

def        lowercase							(		lowerCAmelCase__ :     str			) ->      int:

		def remove_articles(lowerCAmelCase__ :     Dict			):
				return ARTICLES_REGEX.sub(''' '''    ,					lowerCAmelCase__			)

		def white_space_fix(lowerCAmelCase__ :     Dict			):
				return " ".join(text.split()			)

		def remove_punc(lowerCAmelCase__ :     Union[str, Any]			):
				__a           =			set(string.punctuation			)
				return "".join(ch for ch in text if ch not in exclude			)

		def lower(lowerCAmelCase__ :     Dict			):
				return text.lower()

		return white_space_fix(remove_articles(remove_punc(lower(lowerCAmelCase__			)			)			)			)

def        lowercase							(		lowerCAmelCase__ :     Tuple			) ->      Tuple:
		if not s:
				return []
		return normalize_answer(lowerCAmelCase__			).split()

def        lowercase							(		lowerCAmelCase__ :     Union[str, Any]    ,					lowerCAmelCase__ :     int			) ->      Optional[Any]:
		return int(normalize_answer(lowerCAmelCase__			) == normalize_answer(lowerCAmelCase__			)			)

def        lowercase							(		lowerCAmelCase__ :     Any    ,					lowerCAmelCase__ :     int			) ->      Tuple:
		__a           =			get_tokens(lowerCAmelCase__			)
		__a           =			get_tokens(lowerCAmelCase__			)
		__a           =			collections.Counter(lowerCAmelCase__			) & collections.Counter(lowerCAmelCase__			)
		__a           =			sum(common.values()			)
		if len(lowerCAmelCase__			) == 0 or len(lowerCAmelCase__			) == 0:
				# If either is no-answer, then F1 is 1 if they agree, 0 otherwise
				return int(gold_toks == pred_toks			)
		if num_same == 0:
				return 0
		__a           =			1.0 * num_same / len(lowerCAmelCase__			)
		__a           =			1.0 * num_same / len(lowerCAmelCase__			)
		__a           =			(2 * precision * recall) / (precision + recall)
		return fa

def        lowercase							(		lowerCAmelCase__ :     Union[str, Any]    ,					lowerCAmelCase__ :     Optional[int]			) ->      Union[str, Any]:
		__a           =			{}
		__a           =			{}
		for article in dataset:
				for p in article["paragraphs"]:
						for qa in p["qas"]:
								__a           =			qa['''id''']
								__a           =			[t for t in qa['''answers''']['''text'''] if normalize_answer(lowerCAmelCase__			)]
								if not gold_answers:
										# For unanswerable questions, only correct answer is empty string
										__a           =			['''''']
								if qid not in preds:
										print(f'''Missing prediction for {qid}'''			)
										continue
								__a           =			preds[qid]
								# Take max over all gold answers
								__a           =			max(compute_exact(lowerCAmelCase__    ,					lowerCAmelCase__			) for a in gold_answers			)
								__a           =			max(compute_fa(lowerCAmelCase__    ,					lowerCAmelCase__			) for a in gold_answers			)
		return exact_scores, fa_scores

def        lowercase							(		lowerCAmelCase__ :     Optional[Any]    ,					lowerCAmelCase__ :     Any    ,					lowerCAmelCase__ :     Optional[Any]    ,					lowerCAmelCase__ :     Optional[Any]			) ->      str:
		__a           =			{}
		for qid, s in scores.items():
				__a           =			na_probs[qid] > na_prob_thresh
				if pred_na:
						__a           =			float(not qid_to_has_ans[qid]			)
				else:
						__a           =			s
		return new_scores

def        lowercase							(		lowerCAmelCase__ :     List[Any]    ,					lowerCAmelCase__ :     Dict    ,					lowerCAmelCase__ :     Any=None			) ->      Union[str, Any]:
		if not qid_list:
				__a           =			len(lowerCAmelCase__			)
				return collections.OrderedDict(
				    [
				        ('''exact''', 100.0 * sum(exact_scores.values()			) / total),
				        ('''f1''', 100.0 * sum(fa_scores.values()			) / total),
				        ('''total''', total),
				    ]			)
		else:
				__a           =			len(lowerCAmelCase__			)
				return collections.OrderedDict(
				    [
				        ('''exact''', 100.0 * sum(exact_scores[k] for k in qid_list			) / total),
				        ('''f1''', 100.0 * sum(fa_scores[k] for k in qid_list			) / total),
				        ('''total''', total),
				    ]			)

def        lowercase							(		lowerCAmelCase__ :     Optional[Any]    ,					lowerCAmelCase__ :     Optional[int]    ,					lowerCAmelCase__ :     Optional[Any]			) ->      List[Any]:
		for k in new_eval:
				__a           =			new_eval[k]

def        lowercase							(		lowerCAmelCase__ :     Optional[int]    ,					lowerCAmelCase__ :     str    ,					lowerCAmelCase__ :     Any    ,					lowerCAmelCase__ :     List[str]			) ->      int:
		plt.step(lowerCAmelCase__    ,					lowerCAmelCase__    ,					color='''b'''    ,					alpha=0.2    ,					where='''post'''			)
		plt.fill_between(lowerCAmelCase__    ,					lowerCAmelCase__    ,					step='''post'''    ,					alpha=0.2    ,					color='''b'''			)
		plt.xlabel('''Recall'''			)
		plt.ylabel('''Precision'''			)
		plt.xlim([0.0, 1.05]			)
		plt.ylim([0.0, 1.05]			)
		plt.title(lowerCAmelCase__			)
		plt.savefig(lowerCAmelCase__			)
		plt.clf()

def        lowercase							(		lowerCAmelCase__ :     Any    ,					lowerCAmelCase__ :     int    ,					lowerCAmelCase__ :     str    ,					lowerCAmelCase__ :     Optional[Any]    ,					lowerCAmelCase__ :     List[Any]=None    ,					lowerCAmelCase__ :     List[Any]=None			) ->      List[str]:
		__a           =			sorted(lowerCAmelCase__    ,					key=lambda lowerCAmelCase__			: na_probs[k]			)
		__a           =			0.0
		__a           =			1.0
		__a           =			0.0
		__a           =			[1.0]
		__a           =			[0.0]
		__a           =			0.0
		for i, qid in enumerate(lowerCAmelCase__			):
				if qid_to_has_ans[qid]:
						true_pos += scores[qid]
				__a           =			true_pos / float(i + 1			)
				__a           =			true_pos / float(lowerCAmelCase__			)
				if i == len(lowerCAmelCase__			) - 1 or na_probs[qid] != na_probs[qid_list[i + 1]]:
						# i.e., if we can put a threshold after this point
						avg_prec += cur_p * (cur_r - recalls[-1])
						precisions.append(lowerCAmelCase__			)
						recalls.append(lowerCAmelCase__			)
		if out_image:
				plot_pr_curve(lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__			)
		return {"ap": 100.0 * avg_prec}

def        lowercase							(		lowerCAmelCase__ :     str    ,					lowerCAmelCase__ :     Dict    ,					lowerCAmelCase__ :     Optional[int]    ,					lowerCAmelCase__ :     Tuple    ,					lowerCAmelCase__ :     Any    ,					lowerCAmelCase__ :     List[Any]			) ->      Tuple:
		if out_image_dir and not os.path.exists(lowerCAmelCase__			):
				os.makedirs(lowerCAmelCase__			)
		__a           =			sum(1 for v in qid_to_has_ans.values() if v			)
		if num_true_pos == 0:
				return
		__a           =			make_precision_recall_eval(
		    lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__    ,					out_image=os.path.join(lowerCAmelCase__    ,					'''pr_exact.png'''			)    ,					title='''Precision-Recall curve for Exact Match score'''    ,					)
		__a           =			make_precision_recall_eval(
		    lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__    ,					out_image=os.path.join(lowerCAmelCase__    ,					'''pr_f1.png'''			)    ,					title='''Precision-Recall curve for F1 score'''    ,					)
		__a           =			{k: float(lowerCAmelCase__			) for k, v in qid_to_has_ans.items()}
		__a           =			make_precision_recall_eval(
		    lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__    ,					out_image=os.path.join(lowerCAmelCase__    ,					'''pr_oracle.png'''			)    ,					title='''Oracle Precision-Recall curve (binary task of HasAns vs. NoAns)'''    ,					)
		merge_eval(lowerCAmelCase__    ,					lowerCAmelCase__    ,					'''pr_exact'''			)
		merge_eval(lowerCAmelCase__    ,					lowerCAmelCase__    ,					'''pr_f1'''			)
		merge_eval(lowerCAmelCase__    ,					lowerCAmelCase__    ,					'''pr_oracle'''			)

def        lowercase							(		lowerCAmelCase__ :     Optional[Any]    ,					lowerCAmelCase__ :     Optional[int]    ,					lowerCAmelCase__ :     List[Any]    ,					lowerCAmelCase__ :     Optional[Any]			) ->      List[str]:
		if not qid_list:
				return
		__a           =			[na_probs[k] for k in qid_list]
		__a           =			np.ones_like(lowerCAmelCase__			) / float(len(lowerCAmelCase__			)			)
		plt.hist(lowerCAmelCase__    ,					weights=lowerCAmelCase__    ,					bins=20    ,					range=(0.0, 1.0)			)
		plt.xlabel('''Model probability of no-answer'''			)
		plt.ylabel('''Proportion of dataset'''			)
		plt.title(f'''Histogram of no-answer probability: {name}'''			)
		plt.savefig(os.path.join(lowerCAmelCase__    ,					f'''na_prob_hist_{name}.png'''			)			)
		plt.clf()

def        lowercase							(		lowerCAmelCase__ :     Union[str, Any]    ,					lowerCAmelCase__ :     Any    ,					lowerCAmelCase__ :     Any    ,					lowerCAmelCase__ :     List[str]			) ->      Union[str, Any]:
		__a           =			sum(1 for k in qid_to_has_ans if not qid_to_has_ans[k]			)
		__a           =			num_no_ans
		__a           =			cur_score
		__a           =			0.0
		__a           =			sorted(lowerCAmelCase__    ,					key=lambda lowerCAmelCase__			: na_probs[k]			)
		for i, qid in enumerate(lowerCAmelCase__			):
				if qid not in scores:
						continue
				if qid_to_has_ans[qid]:
						__a           =			scores[qid]
				else:
						if preds[qid]:
								__a           =			-1
						else:
								__a           =			0
				cur_score += diff
				if cur_score > best_score:
						__a           =			cur_score
						__a           =			na_probs[qid]
		return 100.0 * best_score / len(lowerCAmelCase__			), best_thresh

def        lowercase							(		lowerCAmelCase__ :     Optional[Any]    ,					lowerCAmelCase__ :     Optional[Any]    ,					lowerCAmelCase__ :     Optional[Any]    ,					lowerCAmelCase__ :     str    ,					lowerCAmelCase__ :     Optional[Any]    ,					lowerCAmelCase__ :     Tuple			) ->      Optional[Any]:
		__a           =			find_best_thresh(lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__			)
		__a           =			find_best_thresh(lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__			)
		__a           =			best_exact
		__a           =			exact_thresh
		__a           =			best_fa
		__a           =			fa_thresh

def        lowercase							(		) ->      Optional[int]:
		with open(OPTS.data_file			) as f:
				__a           =			json.load(lowerCAmelCase__			)
				__a           =			dataset_json['''data''']
		with open(OPTS.pred_file			) as f:
				__a           =			json.load(lowerCAmelCase__			)
		if OPTS.na_prob_file:
				with open(OPTS.na_prob_file			) as f:
						__a           =			json.load(lowerCAmelCase__			)
		else:
				__a           =			{k: 0.0 for k in preds}
		__a           =			make_qid_to_has_ans(lowerCAmelCase__			)  # maps qid to True/False
		__a           =			[k for k, v in qid_to_has_ans.items() if v]
		__a           =			[k for k, v in qid_to_has_ans.items() if not v]
		__a           =			get_raw_scores(lowerCAmelCase__    ,					lowerCAmelCase__			)
		__a           =			apply_no_ans_threshold(lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__    ,					OPTS.na_prob_thresh			)
		__a           =			apply_no_ans_threshold(lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__    ,					OPTS.na_prob_thresh			)
		__a           =			make_eval_dict(lowerCAmelCase__    ,					lowerCAmelCase__			)
		if has_ans_qids:
				__a           =			make_eval_dict(lowerCAmelCase__    ,					lowerCAmelCase__    ,					qid_list=lowerCAmelCase__			)
				merge_eval(lowerCAmelCase__    ,					lowerCAmelCase__    ,					'''HasAns'''			)
		if no_ans_qids:
				__a           =			make_eval_dict(lowerCAmelCase__    ,					lowerCAmelCase__    ,					qid_list=lowerCAmelCase__			)
				merge_eval(lowerCAmelCase__    ,					lowerCAmelCase__    ,					'''NoAns'''			)
		if OPTS.na_prob_file:
				find_all_best_thresh(lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__			)
		if OPTS.na_prob_file and OPTS.out_image_dir:
				run_precision_recall_analysis(lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__    ,					lowerCAmelCase__    ,					OPTS.out_image_dir			)
				histogram_na_prob(lowerCAmelCase__    ,					lowerCAmelCase__    ,					OPTS.out_image_dir    ,					'''hasAns'''			)
				histogram_na_prob(lowerCAmelCase__    ,					lowerCAmelCase__    ,					OPTS.out_image_dir    ,					'''noAns'''			)
		if OPTS.out_file:
				with open(OPTS.out_file    ,					'''w'''			) as f:
						json.dump(lowerCAmelCase__    ,					lowerCAmelCase__			)
		else:
				print(json.dumps(lowerCAmelCase__    ,					indent=2			)			)


if __name__ == "__main__":
				lowercase_			     =  parse_args()
				if OPTS.out_image_dir:
								import matplotlib

								matplotlib.use("Agg")
								import matplotlib.pyplot as plt
				main()










import copy
import tempfile
import unittest

from huggingface_hub import HfFolder, delete_repo
from parameterized import parameterized
from requests.exceptions import HTTPError

from transformers import AutoConfig, GenerationConfig
from transformers.testing_utils import TOKEN, USER, is_staging_test






class   _lowerCamelCase (					unittest.TestCase			):




       """simple docstring"""



       @parameterized.expand([(None,), ('''foo.json''',)]		)
       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE		)->Tuple:




         '''simple docstring'''





         A_      :				Dict		     =					GenerationConfig(
             do_sample=_SCREAMING_SNAKE_CASE				,       temperature=0.7				,       length_penalty=1.0				,       bad_words_ids=[[1, 2, 3], [4, 5]]				,       )
         with tempfile.TemporaryDirectory() as tmp_dir:
           config.save_pretrained(_SCREAMING_SNAKE_CASE				,       config_name=_SCREAMING_SNAKE_CASE		)
           A_      :				Tuple		     =					GenerationConfig.from_pretrained(_SCREAMING_SNAKE_CASE				,       config_name=_SCREAMING_SNAKE_CASE		)

         # Checks parameters that were specified
         self.assertEqual(loaded_config.do_sample				,       _SCREAMING_SNAKE_CASE		)
         self.assertEqual(loaded_config.temperature				,       0.7		)
         self.assertEqual(loaded_config.length_penalty				,       1.0		)
         self.assertEqual(loaded_config.bad_words_ids				,       [[1, 2, 3], [4, 5]]		)

         # Checks parameters that were not specified (defaults)
         self.assertEqual(loaded_config.top_k				,       50		)
         self.assertEqual(loaded_config.max_length				,       20		)
         self.assertEqual(loaded_config.max_time				,       _SCREAMING_SNAKE_CASE		)



       def        _snake_case       (      self		)->Dict:




         '''simple docstring'''





         A_      :				str		     =					AutoConfig.from_pretrained('''gpt2'''		)
         A_      :				int		     =					GenerationConfig.from_model_config(_SCREAMING_SNAKE_CASE		)
         A_      :				Dict		     =					GenerationConfig()

         # The generation config has loaded a few non-default parameters from the model config
         self.assertNotEqual(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)

         # One of those parameters is eos_token_id -- check if it matches
         self.assertNotEqual(generation_config_from_model.eos_token_id				,       default_generation_config.eos_token_id		)
         self.assertEqual(generation_config_from_model.eos_token_id				,       model_config.eos_token_id		)



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




         '''simple docstring'''





         A_      :				List[Any]		     =					GenerationConfig()
         A_      :				Optional[Any]		     =					{
             '''max_new_tokens''': 1024,
             '''foo''': '''bar''',
         }
         A_      :				Dict		     =					copy.deepcopy(_SCREAMING_SNAKE_CASE		)
         A_      :				Optional[int]		     =					generation_config.update(**_SCREAMING_SNAKE_CASE		)

         # update_kwargs was not modified (no side effects)
         self.assertEqual(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)

         # update_kwargs was used to update the config on valid attributes
         self.assertEqual(generation_config.max_new_tokens				,       1024		)

         # `.update()` returns a dictionary of unused kwargs
         self.assertEqual(_SCREAMING_SNAKE_CASE				,       {'''foo''': '''bar'''}		)



       def        _snake_case       (      self		)->str:




         '''simple docstring'''





         A_      :				List[str]		     =					GenerationConfig()
         A_      :				int		     =					'''bar'''

         with tempfile.TemporaryDirectory('''test-generation-config'''		) as tmp_dir:
           generation_config.save_pretrained(_SCREAMING_SNAKE_CASE		)

           A_      :				Optional[Any]		     =					GenerationConfig.from_pretrained(_SCREAMING_SNAKE_CASE		)
         # update_kwargs was used to update the config on valid attributes
         self.assertEqual(new_config.foo				,       '''bar'''		)

         A_      :				Optional[int]		     =					GenerationConfig.from_model_config(_SCREAMING_SNAKE_CASE		)
         assert not hasattr(_SCREAMING_SNAKE_CASE				,       '''foo'''		)  # no new kwargs should be initialized if from config







       def        _snake_case       (      self		)->List[Any]:




         '''simple docstring'''





         A_      :				str		     =					GenerationConfig()
         self.assertEqual(default_config.temperature				,       1.0		)
         self.assertEqual(default_config.do_sample				,       _SCREAMING_SNAKE_CASE		)
         self.assertEqual(default_config.num_beams				,       1		)

         A_      :				str		     =					GenerationConfig(
             do_sample=_SCREAMING_SNAKE_CASE				,       temperature=0.7				,       length_penalty=1.0				,       bad_words_ids=[[1, 2, 3], [4, 5]]				,       )
         self.assertEqual(config.temperature				,       0.7		)
         self.assertEqual(config.do_sample				,       _SCREAMING_SNAKE_CASE		)
         self.assertEqual(config.num_beams				,       1		)

         with tempfile.TemporaryDirectory() as tmp_dir:
           config.save_pretrained(_SCREAMING_SNAKE_CASE		)
           A_      :				Dict		     =					GenerationConfig.from_pretrained(_SCREAMING_SNAKE_CASE				,       temperature=1.0		)

         self.assertEqual(loaded_config.temperature				,       1.0		)
         self.assertEqual(loaded_config.do_sample				,       _SCREAMING_SNAKE_CASE		)
         self.assertEqual(loaded_config.num_beams				,       1		)  # default value






@is_staging_test
class   _lowerCamelCase (					unittest.TestCase			):




       """simple docstring"""



       @classmethod
       def        _snake_case       (      cls		)->Optional[int]:




         '''simple docstring'''





         A_      :				str		     =					TOKEN
         HfFolder.save_token(_SCREAMING_SNAKE_CASE		)



       @classmethod
       def        _snake_case       (      cls		)->List[Any]:




         '''simple docstring'''





         try:
           delete_repo(token=cls._token				,       repo_id='''test-generation-config'''		)
         except HTTPError:
           pass

         try:
           delete_repo(token=cls._token				,       repo_id='''valid_org/test-generation-config-org'''		)
         except HTTPError:
           pass



       def        _snake_case       (      self		)->List[Any]:




         '''simple docstring'''





         A_      :				List[Any]		     =					GenerationConfig(
             do_sample=_SCREAMING_SNAKE_CASE				,       temperature=0.7				,       length_penalty=1.0				,       )
         config.push_to_hub('''test-generation-config'''				,       use_auth_token=self._token		)

         A_      :				Optional[int]		     =					GenerationConfig.from_pretrained(F'''{USER}/test-generation-config'''		)
         for k, v in config.to_dict().items():
           if k != "transformers_version":
             self.assertEqual(_SCREAMING_SNAKE_CASE				,       getattr(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)		)

        # Reset repo
         delete_repo(token=self._token				,       repo_id='''test-generation-config'''		)

         # Push to hub via save_pretrained
         with tempfile.TemporaryDirectory() as tmp_dir:
           config.save_pretrained(
               _SCREAMING_SNAKE_CASE				,       repo_id='''test-generation-config'''				,       push_to_hub=_SCREAMING_SNAKE_CASE				,       use_auth_token=self._token		)

         A_      :				Optional[Any]		     =					GenerationConfig.from_pretrained(F'''{USER}/test-generation-config'''		)
         for k, v in config.to_dict().items():
           if k != "transformers_version":
             self.assertEqual(_SCREAMING_SNAKE_CASE				,       getattr(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)		)







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




         '''simple docstring'''





         A_      :				Tuple		     =					GenerationConfig(
             do_sample=_SCREAMING_SNAKE_CASE				,       temperature=0.7				,       length_penalty=1.0				,       )
         config.push_to_hub('''valid_org/test-generation-config-org'''				,       use_auth_token=self._token		)

         A_      :				Union[str, Any]		     =					GenerationConfig.from_pretrained('''valid_org/test-generation-config-org'''		)
         for k, v in config.to_dict().items():
           if k != "transformers_version":
             self.assertEqual(_SCREAMING_SNAKE_CASE				,       getattr(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)		)

        # Reset repo
         delete_repo(token=self._token				,       repo_id='''valid_org/test-generation-config-org'''		)

         # Push to hub via save_pretrained
         with tempfile.TemporaryDirectory() as tmp_dir:
           config.save_pretrained(
               _SCREAMING_SNAKE_CASE				,       repo_id='''valid_org/test-generation-config-org'''				,       push_to_hub=_SCREAMING_SNAKE_CASE				,       use_auth_token=self._token		)

         A_      :				Dict		     =					GenerationConfig.from_pretrained('''valid_org/test-generation-config-org'''		)
         for k, v in config.to_dict().items():
           if k != "transformers_version":
             self.assertEqual(_SCREAMING_SNAKE_CASE				,       getattr(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)		)




